@@ -3,7 +3,6 @@ module Adapter
3
3
class Attributes < Base
4
4
def initialize ( serializer , options = { } )
5
5
super
6
- @cached_attributes = options [ :cache_attributes ] || { }
7
6
@include_directive =
8
7
if options [ :include_directive ]
9
8
options [ :include_directive ]
@@ -27,7 +26,7 @@ def serializable_hash(options = nil)
27
26
private
28
27
29
28
def serializable_hash_for_collection ( options )
30
- cache_attributes
29
+ instance_options [ :cached_attributes ] ||= ActiveModel :: Serializer . cache_read_multi ( serializer , self , @include_directive )
31
30
opts = instance_options . merge ( include_directive : @include_directive )
32
31
serializer . map { |s | Attributes . new ( s , opts ) . serializable_hash ( options ) }
33
32
end
@@ -62,16 +61,11 @@ def relationship_value_for(association, options)
62
61
relationship_value
63
62
end
64
63
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
-
72
64
def resource_object_for ( options )
73
65
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
75
69
serializer . cached_fields ( options [ :fields ] , self )
76
70
end
77
71
else
0 commit comments