aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorschneems <richard.schneeman+foo@gmail.com>2018-09-20 13:56:07 -0500
committerschneems <richard.schneeman+foo@gmail.com>2018-09-20 15:31:38 -0500
commit135d3e15b72b9820212027b057df8980140a947b (patch)
tree3d2b41d17c4603aced3a9d414af27327b95e2229 /activerecord
parentb45b96b91fc62e7488002cb05c96ec78577f7873 (diff)
downloadrails-135d3e15b72b9820212027b057df8980140a947b.tar.gz
rails-135d3e15b72b9820212027b057df8980140a947b.tar.bz2
rails-135d3e15b72b9820212027b057df8980140a947b.zip
[close #33907] Error when using "recyclable" cache keys with a store that does not support it
If you are using the "in cache versioning" also known as "recyclable cache keys" the cache store must be aware of this scheme, otherwise you will generate cache entries that never invalidate. This PR adds a check to the initialization process to ensure that if recyclable cache keys are being used via ``` config.active_record.cache_versioning = true ``` Then the cache store needs to show that it supports this versioning scheme. Cache stores can let Rails know that they support this scheme by adding a method `supports_in_cache_versioning?` and returning true.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/railtie.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index b213754641..fcee3de0b7 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -88,6 +88,29 @@ module ActiveRecord
end
end
+ initializer "Check for cache versioning support" do
+ config.after_initialize do |app|
+ ActiveSupport.on_load(:active_record) do
+ if app.config.active_record.cache_versioning && Rails.cache
+ unless Rails.cache.try(:supports_in_cache_versioning?)
+ raise <<-end_error
+
+You're using a cache store `#{Rails.cache.class}` that does not support
+"recyclable" cache keys, also known as "in cache versioning". To
+fix this issue either disable "recyclable" cache keys by setting:
+
+ config.active_record.cache_versioning = false
+
+Or switching to a cache store that supports this functionality:
+https://guides.rubyonrails.org/caching_with_rails.html#cache-stores
+
+end_error
+ end
+ end
+ end
+ end
+ end
+
initializer "active_record.check_schema_cache_dump" do
if config.active_record.delete(:use_schema_cache_dump)
config.after_initialize do |app|