mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
@@ -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 = {}
|
||||
base._associations = {}
|
||||
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