diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2012-11-26 00:59:48 -0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2012-11-26 00:59:48 -0800 |
commit | 1081ae20fb1d23b27e21e3e9f1de62253e34804f (patch) | |
tree | 2ad09cdf2484d9dc3edc13423b0b0547a285dd83 /actionpack/lib | |
parent | dc973e78560a6514ab172f0ee86dc84a9147d39a (diff) | |
parent | 7fb8c670474cf553a3540ac283d30dba02d9ea61 (diff) | |
download | rails-1081ae20fb1d23b27e21e3e9f1de62253e34804f.tar.gz rails-1081ae20fb1d23b27e21e3e9f1de62253e34804f.tar.bz2 rails-1081ae20fb1d23b27e21e3e9f1de62253e34804f.zip |
Merge pull request #8317 from latortuga/cache-digest-opt-out
Add explicit opt-out for fragment cache digesting
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/cache_helper.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb index ddac87a37d..fbaba63997 100644 --- a/actionpack/lib/action_view/helpers/cache_helper.rb +++ b/actionpack/lib/action_view/helpers/cache_helper.rb @@ -52,6 +52,13 @@ module ActionView # Additionally, the digestor will automatically look through your template file for # explicit and implicit dependencies, and include those as part of the digest. # + # The digestor can be bypassed by passing skip_digest: true as an option to the cache call: + # + # <% cache project, skip_digest: true do %> + # <b>All the topics on this project</b> + # <%= render project.topics %> + # <% end %> + # # ==== Implicit dependencies # # Most template dependencies can be derived from calls to render in the template itself. @@ -105,7 +112,7 @@ module ActionView # Now all you'll have to do is change that timestamp when the helper method changes. def cache(name = {}, options = nil, &block) if controller.perform_caching - safe_concat(fragment_for(fragment_name_with_digest(name), options, &block)) + safe_concat(fragment_for(cache_fragment_name(name, options), options, &block)) else yield end @@ -113,6 +120,21 @@ module ActionView nil end + # This helper returns the name of a cache key for a given fragment cache + # call. By supplying skip_digest: true to cache, the digestion of cache + # fragments can be manually bypassed. This is useful when cache fragments + # cannot be manually expired unless you know the exact key which is the + # case when using memcached. + def cache_fragment_name(name = {}, options = nil) + skip_digest = options && options.delete(:skip_digest) + + if skip_digest + name + else + fragment_name_with_digest(name) + end + end + def fragment_name_with_digest(name) #:nodoc: if @virtual_path [ |