123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Cacheable

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ActiveSupport::Concern
Defined in: lib/mongoid/cacheable.rb

Overview

Encapsulates behavior around caching.

Instance Method Summary

DSL Calls

included

[ GitHub ]


10
11
12
13
# File 'lib/mongoid/cacheable.rb', line 10

included do
  cattr_accessor :cache_timestamp_format, instance_writer: false
  self.cache_timestamp_format = :nsec
end

Instance Method Details

#cache_keyString

Print out the cache key. This will append different values on the plural model name.

If new_record? - will append /new If not - will append /id-updated_at.to_formatted_s(cache_timestamp_format) Without updated_at - will append /id

This is usually called inside a cache() block

Examples:

Returns the cache key

document.cache_key

Returns:

  • (String)

    the string with or without updated_at

[ GitHub ]

  
# File 'lib/mongoid/cacheable.rb', line 28

def cache_key
  return "#{model_key}/new" if new_record?
  return "#{model_key}/#{_id}-#{updated_at.utc.to_formatted_s(cache_timestamp_format)}" if try(:updated_at)
  "#{model_key}/#{_id}"
end