Module: Toy::Caching

Extended by:
ActiveSupport::Concern
Included in:
Store
Defined in:
lib/toy/caching.rb

Instance Method Summary collapse

Instance Method Details

#cache_key(*suffixes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/toy/caching.rb', line 5

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