mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Have to opt in with #cache_key
This commit is contained in:
parent
e923174a26
commit
535a33a33b
@ -441,17 +441,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def perform_caching?
|
||||
perform_caching && cache && cache_key
|
||||
end
|
||||
|
||||
# Override this method if you want to create a key based on associations
|
||||
# Here's an example: your serializer has associations and the scope
|
||||
#
|
||||
# def cache_key
|
||||
# [ object, scope, scope.comments ]
|
||||
# end
|
||||
def cache_key
|
||||
object.try :cache_key
|
||||
perform_caching && cache && try(:cache_key)
|
||||
end
|
||||
|
||||
def expand_cache_key(*args)
|
||||
|
||||
@ -30,10 +30,6 @@ class CachingTest < ActiveModel::TestCase
|
||||
%w(ruby)
|
||||
end
|
||||
|
||||
def cache_key
|
||||
name
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
send name
|
||||
end
|
||||
@ -61,6 +57,10 @@ class CachingTest < ActiveModel::TestCase
|
||||
def self.to_s
|
||||
'serializer'
|
||||
end
|
||||
|
||||
def cache_key
|
||||
object.name
|
||||
end
|
||||
end
|
||||
|
||||
serializer.cache = NullStore.new
|
||||
@ -82,6 +82,10 @@ class CachingTest < ActiveModel::TestCase
|
||||
def self.to_s
|
||||
'serializer'
|
||||
end
|
||||
|
||||
def cache_key
|
||||
object.name
|
||||
end
|
||||
end
|
||||
|
||||
serializer.cache = NullStore.new
|
||||
|
||||
Loading…
Reference in New Issue
Block a user