Skip to content

Commit b0039e3

Browse files
committed
Update caching.rb
1 parent 70604bb commit b0039e3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/active_model/serializer/concerns/caching.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def fetch_attributes(fields, cached_attributes, adapter_instance)
231231
def fetch(adapter_instance, cache_options = serializer_class._cache_options, key = nil)
232232
if serializer_class.cache_store
233233
key ||= cache_key(adapter_instance)
234+
cache_options = cache_options.merge(version: object_cache_version) if object_cache_version
234235
serializer_class.cache_store.fetch(key, cache_options) do
235236
yield
236237
end
@@ -280,12 +281,14 @@ def expand_cache_key(parts)
280281
ActiveSupport::Cache.expand_cache_key(parts)
281282
end
282283

284+
def object_cache_version
285+
object.cache_version if object.respond_to?(:cache_version)
286+
end
287+
283288
# Use object's cache_key if available, else derive a key from the object
284289
# Pass the `key` option to the `cache` declaration or override this method to customize the cache key
285290
def object_cache_key
286-
if object.respond_to?(:cache_key_with_version)
287-
object.cache_key_with_version
288-
elsif object.respond_to?(:cache_key)
291+
if object.respond_to?(:cache_key)
289292
object.cache_key
290293
elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
291294
object_time_safe = object.updated_at

0 commit comments

Comments
 (0)