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
This commit is contained in:
cintamani 2018-10-01 13:20:50 +01:00
parent 22f2cb76dd
commit be5fbf3d54

View File

@ -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