From be5fbf3d54261b21a9cdfdb509780926219b573f Mon Sep 17 00:00:00 2001 From: cintamani Date: Mon, 1 Oct 2018 13:20:50 +0100 Subject: [PATCH] Use `#cache_key_with_key` when available In order to keep compatibility between the AMS cache feature and with Rails > 5.1 cache versioning, we have to use the `cache_key_with_version`. **NOTE** - This is a quick fix to the issue, if there will be future plans a proper cache versioning with recyclable key needs to be implemented. More info: https://github.com/rails-api/active_model_serializers/issues/2287 --- lib/active_model/serializer/concerns/caching.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_model/serializer/concerns/caching.rb b/lib/active_model/serializer/concerns/caching.rb index ff72ca01..35bd8e64 100644 --- a/lib/active_model/serializer/concerns/caching.rb +++ b/lib/active_model/serializer/concerns/caching.rb @@ -283,7 +283,9 @@ module ActiveModel # 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 object_cache_key - if object.respond_to?(:cache_key) + if object.respond_to?(:cache_key_with_version) + object.cache_key_with_version + elsif object.respond_to?(:cache_key) object.cache_key elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key])) object_time_safe = object.updated_at