Module: MarkMapper::Plugins::Caching

Extended by:
ActiveSupport::Concern
Included in:
Document, EmbeddedDocument
Defined in:
lib/mark_mapper/plugins/caching.rb

Instance Method Summary collapse

Instance Method Details

#cache_key(*suffixes) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mark_mapper/plugins/caching.rb', line 7

def cache_key(*suffixes)
  cache_key = case
                when !persisted?
                  "#{self.class.name}/new"
                when timestamp = self[:updated_at]
                  "#{self.class.name}/#{id}-#{timestamp.to_s(:number)}"
                else
                  "#{self.class.name}/#{id}"
              end
  cache_key += "/#{suffixes.join('/')}" unless suffixes.empty?
  cache_key
end