Sha256: 22412ff5d81ba5ea65b94d9a0dd48c0b0250e676b2f8832080f57e019b61c24e

Contents?: true

Size: 1003 Bytes

Versions: 38

Compression:

Stored size: 1003 Bytes

Contents

# encoding: utf-8
module Mongoid

  # Encapsulates behaviour around caching.
  #
  # @since 6.0.0
  module Cacheable
    extend ActiveSupport::Concern

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

    # 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_s(cache_timestamp_format)
    # Without updated_at - will append /id
    #
    # This is usually called insode a cache() block
    #
    # @example Returns the cache key
    #   document.cache_key
    #
    # @return [ String ] the string with or without updated_at
    #
    # @since 2.4.0
    def cache_key
      return "#{model_key}/new" if new_record?
      return "#{model_key}/#{id}-#{updated_at.utc.to_s(cache_timestamp_format)}" if do_or_do_not(:updated_at)
      "#{model_key}/#{id}"
    end
  end
end

Version data entries

38 entries across 36 versions & 2 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/cacheable.rb
mongoid-7.0.12 lib/mongoid/cacheable.rb
mongoid-6.4.8 lib/mongoid/cacheable.rb
mongoid-7.0.11 lib/mongoid/cacheable.rb
mongoid-7.0.10 lib/mongoid/cacheable.rb
mongoid-6.4.7 lib/mongoid/cacheable.rb
mongoid-6.4.5 lib/mongoid/cacheable.rb
mongoid-7.0.8 lib/mongoid/cacheable.rb
mongoid-7.0.7 lib/mongoid/cacheable.rb
mongoid-7.0.6 lib/mongoid/cacheable.rb
mongoid-7.0.5 lib/mongoid/cacheable.rb
mongoid-7.0.4 lib/mongoid/cacheable.rb
mongoid-6.4.4 lib/mongoid/cacheable.rb
mongoid-7.0.3 lib/mongoid/cacheable.rb
mongoid-6.4.2 lib/mongoid/cacheable.rb
mongoid-7.0.2 lib/mongoid/cacheable.rb
mongoid-7.0.1 lib/mongoid/cacheable.rb
mongoid-6.4.1 lib/mongoid/cacheable.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/lib/mongoid/cacheable.rb
mongoid-7.0.0 lib/mongoid/cacheable.rb