Skip to content

Commit 3424bd8

Browse files
committed
Switch to supports_cache_versioning? check to a class method
- Moving the `supports_cache_versioning?` check to a class method. - Shorten the method doc. - Expand on the error message.
1 parent 135d3e1 commit 3424bd8

File tree

8 files changed

+23
-29
lines changed

8 files changed

+23
-29
lines changed

activerecord/lib/active_record/railtie.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,19 @@ class Railtie < Rails::Railtie # :nodoc:
9292
config.after_initialize do |app|
9393
ActiveSupport.on_load(:active_record) do
9494
if app.config.active_record.cache_versioning && Rails.cache
95-
unless Rails.cache.try(:supports_in_cache_versioning?)
95+
unless Rails.cache.class.try(:supports_cache_versioning?)
9696
raise <<-end_error
9797
98-
You're using a cache store `#{Rails.cache.class}` that does not support
99-
"recyclable" cache keys, also known as "in cache versioning". To
100-
fix this issue either disable "recyclable" cache keys by setting:
98+
You're using a cache store that doesn't support native cache versioning.
99+
Your best option is to upgrade to a newer version of #{Rails.cache.class}
100+
that supports cache versioning (#{Rails.cache.class}.supports_cache_versioning? #=> true).
101101
102-
config.active_record.cache_versioning = false
102+
Next best, switch to a different cache store that does support cache versioning:
103+
https://guides.rubyonrails.org/caching_with_rails.html#cache-stores.
104+
105+
To keep using the current cache store, you can turn off cache versioning entirely:
103106
104-
Or switching to a cache store that supports this functionality:
105-
https://guides.rubyonrails.org/caching_with_rails.html#cache-stores
107+
config.active_record.cache_versioning = false
106108
107109
end_error
108110
end

activesupport/lib/active_support/cache/file_store.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ def initialize(cache_path, options = nil)
2626
@cache_path = cache_path.to_s
2727
end
2828

29-
# Advertise that this cache store can be used
30-
# with "recyclable cache keys" otherwise known
31-
# as cache versioning.
32-
def supports_in_cache_versioning?
29+
# Advertise cache versioning support.
30+
def self.supports_cache_versioning?
3331
true
3432
end
3533

activesupport/lib/active_support/cache/mem_cache_store.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ def write_entry(key, entry, options)
4747
end
4848
end
4949

50-
# Advertise that this cache store can be used
51-
# with "recyclable cache keys" otherwise known
52-
# as cache versioning.
53-
def supports_in_cache_versioning?
50+
# Advertise cache versioning support.
51+
def self.supports_cache_versioning?
5452
true
5553
end
5654

activesupport/lib/active_support/cache/memory_store.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ def initialize(options = nil)
3030
@pruning = false
3131
end
3232

33-
# Advertise that this cache store can be used
34-
# with "recyclable cache keys" otherwise known
35-
# as cache versioning.
36-
def supports_in_cache_versioning?
33+
# Advertise cache versioning support.
34+
def self.supports_cache_versioning?
3735
true
3836
end
3937

activesupport/lib/active_support/cache/null_store.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ module Cache
1212
class NullStore < Store
1313
prepend Strategy::LocalCache
1414

15-
# Advertise that this cache store can be used
16-
# with "recyclable cache keys" otherwise known
17-
# as cache versioning.
18-
def supports_in_cache_versioning?
15+
# Advertise cache versioning support.
16+
def self.supports_cache_versioning?
1917
true
2018
end
2119

activesupport/lib/active_support/cache/redis_cache_store.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ class RedisCacheStore < Store
6666
SCAN_BATCH_SIZE = 1000
6767
private_constant :SCAN_BATCH_SIZE
6868

69-
# Advertise that this cache store can be used
70-
# with "recyclable cache keys" otherwise known
71-
# as cache versioning.
72-
def supports_in_cache_versioning?
69+
# Advertise cache versioning support.
70+
def self.supports_cache_versioning?
7371
true
7472
end
7573

railties/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
* Raise an error when "recyclable cache keys" are being used by a cache store
2-
that does not explicitly support it.
2+
that does not explicitly support it. Custom cache keys that do support this feature
3+
can bypass this error by implementing the `supports_cache_versioning?` method on their
4+
class and returning a truthy value.
35

46
*Richard Schneeman*
57

railties/test/application/configuration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class MyLogger < ::Logger
133133
app "production"
134134
end
135135

136-
assert_match(/You're using a cache store/, error.message)
136+
assert_match(/You're using a cache/, error.message)
137137
end
138138

139139
test "a renders exception on pending migration" do

0 commit comments

Comments
 (0)