mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
135d3e15b7
commit
3424bd83d6
8 changed files with 23 additions and 29 deletions
|
@ -92,18 +92,20 @@ module ActiveRecord
|
|||
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?)
|
||||
unless Rails.cache.class.try(:supports_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:
|
||||
You're using a cache store that doesn't support native cache versioning.
|
||||
Your best option is to upgrade to a newer version of #{Rails.cache.class}
|
||||
that supports cache versioning (#{Rails.cache.class}.supports_cache_versioning? #=> true).
|
||||
|
||||
Next best, switch to a different cache store that does support cache versioning:
|
||||
https://guides.rubyonrails.org/caching_with_rails.html#cache-stores.
|
||||
|
||||
To keep using the current cache store, you can turn off cache versioning entirely:
|
||||
|
||||
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
|
||||
|
|
|
@ -26,10 +26,8 @@ module ActiveSupport
|
|||
@cache_path = cache_path.to_s
|
||||
end
|
||||
|
||||
# Advertise that this cache store can be used
|
||||
# with "recyclable cache keys" otherwise known
|
||||
# as cache versioning.
|
||||
def supports_in_cache_versioning?
|
||||
# Advertise cache versioning support.
|
||||
def self.supports_cache_versioning?
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -47,10 +47,8 @@ module ActiveSupport
|
|||
end
|
||||
end
|
||||
|
||||
# Advertise that this cache store can be used
|
||||
# with "recyclable cache keys" otherwise known
|
||||
# as cache versioning.
|
||||
def supports_in_cache_versioning?
|
||||
# Advertise cache versioning support.
|
||||
def self.supports_cache_versioning?
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -30,10 +30,8 @@ module ActiveSupport
|
|||
@pruning = false
|
||||
end
|
||||
|
||||
# Advertise that this cache store can be used
|
||||
# with "recyclable cache keys" otherwise known
|
||||
# as cache versioning.
|
||||
def supports_in_cache_versioning?
|
||||
# Advertise cache versioning support.
|
||||
def self.supports_cache_versioning?
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -12,10 +12,8 @@ module ActiveSupport
|
|||
class NullStore < Store
|
||||
prepend Strategy::LocalCache
|
||||
|
||||
# Advertise that this cache store can be used
|
||||
# with "recyclable cache keys" otherwise known
|
||||
# as cache versioning.
|
||||
def supports_in_cache_versioning?
|
||||
# Advertise cache versioning support.
|
||||
def self.supports_cache_versioning?
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -66,10 +66,8 @@ module ActiveSupport
|
|||
SCAN_BATCH_SIZE = 1000
|
||||
private_constant :SCAN_BATCH_SIZE
|
||||
|
||||
# Advertise that this cache store can be used
|
||||
# with "recyclable cache keys" otherwise known
|
||||
# as cache versioning.
|
||||
def supports_in_cache_versioning?
|
||||
# Advertise cache versioning support.
|
||||
def self.supports_cache_versioning?
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
* Raise an error when "recyclable cache keys" are being used by a cache store
|
||||
that does not explicitly support it.
|
||||
that does not explicitly support it. Custom cache keys that do support this feature
|
||||
can bypass this error by implementing the `supports_cache_versioning?` method on their
|
||||
class and returning a truthy value.
|
||||
|
||||
*Richard Schneeman*
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ module ApplicationTests
|
|||
app "production"
|
||||
end
|
||||
|
||||
assert_match(/You're using a cache store/, error.message)
|
||||
assert_match(/You're using a cache/, error.message)
|
||||
end
|
||||
|
||||
test "a renders exception on pending migration" do
|
||||
|
|
Loading…
Reference in a new issue