mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Update caching.rb
This commit is contained in:
parent
70604bbae7
commit
b0039e3758
@ -231,6 +231,7 @@ module ActiveModel
|
|||||||
def fetch(adapter_instance, cache_options = serializer_class._cache_options, key = nil)
|
def fetch(adapter_instance, cache_options = serializer_class._cache_options, key = nil)
|
||||||
if serializer_class.cache_store
|
if serializer_class.cache_store
|
||||||
key ||= cache_key(adapter_instance)
|
key ||= cache_key(adapter_instance)
|
||||||
|
cache_options = cache_options.merge(version: object_cache_version) if object_cache_version
|
||||||
serializer_class.cache_store.fetch(key, cache_options) do
|
serializer_class.cache_store.fetch(key, cache_options) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
@ -280,12 +281,14 @@ module ActiveModel
|
|||||||
ActiveSupport::Cache.expand_cache_key(parts)
|
ActiveSupport::Cache.expand_cache_key(parts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def object_cache_version
|
||||||
|
object.cache_version if object.respond_to?(:cache_version)
|
||||||
|
end
|
||||||
|
|
||||||
# Use object's cache_key if available, else derive a key from the object
|
# 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
|
# Pass the `key` option to the `cache` declaration or override this method to customize the cache key
|
||||||
def object_cache_key
|
def object_cache_key
|
||||||
if object.respond_to?(:cache_key_with_version)
|
if object.respond_to?(:cache_key)
|
||||||
object.cache_key_with_version
|
|
||||||
elsif object.respond_to?(:cache_key)
|
|
||||||
object.cache_key
|
object.cache_key
|
||||||
elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
|
elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
|
||||||
object_time_safe = object.updated_at
|
object_time_safe = object.updated_at
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user