Have to opt in with #cache_key

This commit is contained in:
twinturbo 2012-07-11 16:51:15 +02:00
parent e923174a26
commit 535a33a33b
2 changed files with 9 additions and 15 deletions

View File

@ -441,17 +441,7 @@ module ActiveModel
end end
def perform_caching? def perform_caching?
perform_caching && cache && cache_key perform_caching && cache && try(: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
end end
def expand_cache_key(*args) def expand_cache_key(*args)

View File

@ -30,10 +30,6 @@ class CachingTest < ActiveModel::TestCase
%w(ruby) %w(ruby)
end end
def cache_key
name
end
def read_attribute_for_serialization(name) def read_attribute_for_serialization(name)
send name send name
end end
@ -61,6 +57,10 @@ class CachingTest < ActiveModel::TestCase
def self.to_s def self.to_s
'serializer' 'serializer'
end end
def cache_key
object.name
end
end end
serializer.cache = NullStore.new serializer.cache = NullStore.new
@ -82,6 +82,10 @@ class CachingTest < ActiveModel::TestCase
def self.to_s def self.to_s
'serializer' 'serializer'
end end
def cache_key
object.name
end
end end
serializer.cache = NullStore.new serializer.cache = NullStore.new