@@ -3,7 +3,6 @@ module Adapter
33 class Attributes < Base
44 def initialize ( serializer , options = { } )
55 super
6- @cached_attributes = options [ :cache_attributes ] || { }
76 @include_directive =
87 if options [ :include_directive ]
98 options [ :include_directive ]
@@ -27,7 +26,7 @@ def serializable_hash(options = nil)
2726 private
2827
2928 def serializable_hash_for_collection ( options )
30- cache_attributes
29+ instance_options [ :cached_attributes ] ||= ActiveModel :: Serializer . cache_read_multi ( serializer , self , @include_directive )
3130 opts = instance_options . merge ( include_directive : @include_directive )
3231 serializer . map { |s | Attributes . new ( s , opts ) . serializable_hash ( options ) }
3332 end
@@ -62,16 +61,11 @@ def relationship_value_for(association, options)
6261 relationship_value
6362 end
6463
65- # Set @cached_attributes
66- def cache_attributes
67- return if @cached_attributes . present?
68-
69- @cached_attributes = ActiveModel ::Serializer . cache_read_multi ( serializer , self , @include_directive )
70- end
71-
7264 def resource_object_for ( options )
7365 if serializer . class . cache_enabled?
74- @cached_attributes . fetch ( serializer . cache_key ( self ) ) do
66+ cached_attributes = instance_options [ :cached_attributes ] || { }
67+ key = serializer . cache_key ( self )
68+ cached_attributes . fetch ( key ) do
7569 serializer . cached_fields ( options [ :fields ] , self )
7670 end
7771 else
0 commit comments