aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-02-12 22:37:11 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2016-02-12 22:37:11 +0100
commita88c5ff96de98b67c75a04711847b3a29c2df411 (patch)
treef764d9b4d5795704e445dbd5eaab0e6bd7076bcb /actionview
parent29e5c2057808c3c32ddf0d2b3d99224037d15a62 (diff)
downloadrails-a88c5ff96de98b67c75a04711847b3a29c2df411.tar.gz
rails-a88c5ff96de98b67c75a04711847b3a29c2df411.tar.bz2
rails-a88c5ff96de98b67c75a04711847b3a29c2df411.zip
Only write to collection cache if we have a callable cache key.
A callable cache key writes to the collection cache under a certain namespace. Which means if we don't have scoped cache key we can just rely on the `cache model_name do` in the templates to cache them. Less writes, more sharing. Add `assert_customer_cached` to better illustrate this in tests, and remove tests which then don't communicate as much.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
index 4bc4147e1b..c353eb0b31 100644
--- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
+++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
@@ -51,10 +51,14 @@ module ActionView
end
def fetch_or_cache_partial(cached_partials, order_by:)
+ rely_on_individual_cache_call = !callable_cache_key?
+
order_by.map do |key|
cached_partials.fetch(key) do
yield.tap do |rendered_partial|
- collection_cache.write(key, rendered_partial, @options[:cache_options])
+ unless rely_on_individual_cache_call
+ collection_cache.write(key, rendered_partial, @options[:cache_options])
+ end
end
end
end