mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #902 from cristianbica/serializer_file_digest
Added serializer file digest to the cache_key
This commit is contained in:
@@ -19,6 +19,7 @@ module ActiveModel
|
||||
attr_accessor :_cache_only
|
||||
attr_accessor :_cache_except
|
||||
attr_accessor :_cache_options
|
||||
attr_accessor :_cache_digest
|
||||
end
|
||||
|
||||
def self.inherited(base)
|
||||
@@ -26,6 +27,8 @@ module ActiveModel
|
||||
base._attributes_keys = self._attributes_keys.try(:dup) || {}
|
||||
base._associations = self._associations.try(:dup) || {}
|
||||
base._urls = []
|
||||
serializer_file = File.open(caller.first[/^[^:]+/])
|
||||
base._cache_digest = Digest::MD5.hexdigest(serializer_file.read)
|
||||
end
|
||||
|
||||
def self.attributes(*attrs)
|
||||
|
||||
@@ -63,6 +63,13 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def cache_key
|
||||
parts = []
|
||||
parts << object_cache_key
|
||||
parts << @klass._cache_digest unless @klass._cache_options && @klass._cache_options[:skip_digest]
|
||||
parts.join("/")
|
||||
end
|
||||
|
||||
def object_cache_key
|
||||
(@klass._cache_key) ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{@cached_serializer.object.updated_at}" : @cached_serializer.object.cache_key
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user