Class: ApplicationSerializer

Inherits:
ActiveModel::Serializer
  • Object
show all
Defined in:
lib/generators/command/templates/application_serializer.rb

Overview

Uses russian doll technique

Instance Method Summary collapse

Instance Method Details

#serializable_hashObject

Cache individual Hash objects before serialization This also makes them available to associated serializers



14
15
16
17
18
# File 'lib/generators/command/templates/application_serializer.rb', line 14

def serializable_hash
  Rails.cache.fetch expand_cache_key(self.class.to_s.underscore, cache_key, 'serilizable-hash') do
    super
  end
end

#to_json(*args) ⇒ Object

Cache entire JSON string



6
7
8
9
10
# File 'lib/generators/command/templates/application_serializer.rb', line 6

def to_json(*args)
  Rails.cache.fetch expand_cache_key(self.class.to_s.underscore, cache_key, 'to-json') do
    super
  end
end