Prefer object.cache_key when available.

This commit is contained in:
Benjamin Fleischer
2016-03-31 13:57:38 -05:00
parent ab6bd600e3
commit 4ba4c298ec
6 changed files with 55 additions and 76 deletions

View File

@@ -58,10 +58,6 @@ module ActiveModel
''.freeze
end
def _skip_digest?
_cache_options && _cache_options[:skip_digest]
end
# @api private
# Used by FragmentCache on the CachedSerializer
# to call attribute methods on the fragmented cached serializer.
@@ -146,18 +142,6 @@ module ActiveModel
(_cache_only && !_cache_except || !_cache_only && _cache_except)
end
end
# Use object's cache_key if available, else derive a key from the object
# Pass the `key` option to the `cache` declaration or override this method to customize the cache key
def cache_key
if object.respond_to?(:cache_key)
object.cache_key
else
object_time_safe = object.updated_at
object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
"#{self.class._cache_key}/#{object.id}-#{object_time_safe}"
end
end
end
end
end