Skip to content

Commit

Permalink
append key to subject
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRay committed Apr 13, 2013
1 parent b0a0599 commit 06143af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/super_cache/dog_pile_filter.rb
Expand Up @@ -49,6 +49,7 @@ def write_cache
expires_in = (options[:expires_in] || 600).to_i
Rails.cache.write(flag_key, expires_in, :raw => true, :expires_in => expires_in)
Rails.cache.write(cache_path, response.body, :raw => true, :expires_in => expires_in * 2)
append_cache_key_to_subject(flag_key, cache_path)
end
end
end
13 changes: 12 additions & 1 deletion lib/super_cache/simple_filter.rb
Expand Up @@ -58,6 +58,17 @@ def cache_miss
def write_cache
Rails.logger.info "Write #{cache_path}"
Rails.cache.write(cache_path, response.body, :raw => true, :expires_in => options[:expires_in])
end
append_cache_key_to_subject(cache_path)
end
def append_cache_key_to_subject(*keys)
if options[:subject].respond_to?(:call)
subjects = Array.wrap(controller.instance_exec(controller, &options[:subject])).flatten.select{|s|s.respond_to?(:append_cached_key)}
subjects.each do |s|
keys.each do |k|
s.append_cache_key k
end
end
end
end
end
end

0 comments on commit 06143af

Please sign in to comment.