@@ -216,65 +216,62 @@ def cache_check(adapter_instance)
216
216
# 1. Create a CachedSerializer and NonCachedSerializer from the serializer class
217
217
# 2. Serialize the above two with the given adapter
218
218
# 3. Pass their serializations to the adapter +::fragment_cache+
219
+ #
220
+ # It will split the serializer into two, one that will be cached and one that will not
221
+ #
222
+ # Given a resource name
223
+ # 1. Dynamically creates a CachedSerializer and NonCachedSerializer
224
+ # for a given class 'name'
225
+ # 2. Call
226
+ # CachedSerializer.cache(serializer._cache_options)
227
+ # CachedSerializer.fragmented(serializer)
228
+ # NonCachedSerializer.cache(serializer._cache_options)
229
+ # 3. Build a hash keyed to the +cached+ and +non_cached+ serializers
230
+ # 4. Call +cached_attributes+ on the serializer class and the above hash
231
+ # 5. Return the hash
232
+ #
233
+ # @example
234
+ # When +name+ is <tt>User::Admin</tt>
235
+ # creates the Serializer classes (if they don't exist).
236
+ # CachedUser_AdminSerializer
237
+ # NonCachedUser_AdminSerializer
238
+ #
239
+ # Given a hash of its cached and non-cached serializers
240
+ # 1. Determine cached attributes from serializer class options
241
+ # 2. Add cached attributes to cached Serializer
242
+ # 3. Add non-cached attributes to non-cached Serializer
219
243
def fetch_fragment_cache ( adapter_instance )
220
- # It will split the serializer into two, one that will be cached and one that will not
221
-
222
- # Given a resource name
223
- # 1. Dynamically creates a CachedSerializer and NonCachedSerializer
224
- # for a given class 'name'
225
- # 2. Call
226
- # CachedSerializer.cache(serializer._cache_options)
227
- # CachedSerializer.fragmented(serializer)
228
- # NonCachedSerializer.cache(serializer._cache_options)
229
- # 3. Build a hash keyed to the +cached+ and +non_cached+ serializers
230
- # 4. Call +cached_attributes+ on the serializer class and the above hash
231
- # 5. Return the hash
232
- #
233
- # @example
234
- # When +name+ is <tt>User::Admin</tt>
235
- # creates the Serializer classes (if they don't exist).
236
- # CachedUser_AdminSerializer
237
- # NonCachedUser_AdminSerializer
238
- #
239
244
serializer_class_name = self . class . name . gsub ( '::' . freeze , '_' . freeze )
240
- cached_serializer = _get_or_create_fragment_serializer "Cached#{ serializer_class_name } "
241
- non_cached_serializer = _get_or_create_fragment_serializer "NonCached#{ serializer_class_name } "
242
-
243
245
self . class . _cache_options ||= { }
244
246
self . class . _cache_options [ :key ] = self . class . _cache_key if self . class . _cache_key
245
- cached_serializer . cache ( self . class . _cache_options )
246
247
247
- cached_serializer . type ( self . class . _type )
248
- non_cached_serializer . type ( self . class . _type )
249
-
250
- non_cached_serializer . fragmented ( self )
251
- cached_serializer . fragmented ( self )
252
-
253
- # Given a hash of its cached and non-cached serializers
254
- # 1. Determine cached attributes from serializer class options
255
- # 2. Add cached attributes to cached Serializer
256
- # 3. Add non-cached attributes to non-cached Serializer
257
248
attributes = self . class . _attributes
258
249
cache_only = self . class . _cache_only
259
250
cached_attributes = cache_only ? cache_only : attributes - self . class . _cache_except
260
251
non_cached_attributes = attributes - cached_attributes
261
252
attributes_keys = self . class . _attributes_keys
262
253
254
+ cached_serializer = _get_or_create_fragment_serializer "Cached#{ serializer_class_name } "
255
+ cached_serializer . cache ( self . class . _cache_options )
256
+ cached_serializer . type ( self . class . _type )
257
+ cached_serializer . fragmented ( self )
263
258
cached_attributes . each do |attribute |
264
259
options = attributes_keys [ attribute ] || { }
265
260
cached_serializer . attribute ( attribute , options )
266
261
end
267
- non_cached_attributes . each do |attribute |
268
- options = attributes_keys [ attribute ] || { }
269
- non_cached_serializer . attribute ( attribute , options )
270
- end
271
-
272
- # Get serializable hash from both
273
262
cached_hash = ActiveModelSerializers ::SerializableResource . new (
274
263
object ,
275
264
serializer : cached_serializer ,
276
265
adapter : adapter_instance . class
277
266
) . serializable_hash
267
+
268
+ non_cached_serializer = _get_or_create_fragment_serializer "NonCached#{ serializer_class_name } "
269
+ non_cached_serializer . type ( self . class . _type )
270
+ non_cached_serializer . fragmented ( self )
271
+ non_cached_attributes . each do |attribute |
272
+ options = attributes_keys [ attribute ] || { }
273
+ non_cached_serializer . attribute ( attribute , options )
274
+ end
278
275
non_cached_hash = ActiveModelSerializers ::SerializableResource . new (
279
276
object ,
280
277
serializer : non_cached_serializer ,
0 commit comments