Class: Api::V5::CuisineSerializer

Inherits:
BaseSerializer show all
Defined in:
app/serializers/api/v5/cuisine_serializer.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Methods inherited from BaseSerializer

#full_attachment_url, #safe_translation_attr

Methods inherited from ApplicationSerializer

decorate_attributes, decorator

Instance Method Details

#object_cache_keyObject

Overrides the default cache key generation method. Ref. github.com/rails-api/active_model_serializers/blob/0-10-stable/lib/active_model/serializer/concerns/caching.rb

Need to overrides the default cache key generation method, because the current cache key generation in the application_serializer is returns the same object, even though the object has been updated.



38
39
40
41
42
43
# File 'app/serializers/api/v5/cuisine_serializer.rb', line 38

def object_cache_key
  object_time_safe = object.updated_at
  object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)

  "#{self.class.name}:#{object.id}:#{I18n.locale}:#{object_time_safe}:#{CityHash.hash32(instance_options)}:#{object.restaurant_tags_totals.cache_key}"
end