模块:Mongoid::Cacheable

扩展方式:
ActiveSupport::Concern
包含在:
可组合
定义于:
lib/mongoid/cacheable.rb

Overview

封装与缓存相关的行为。

实例方法摘要折叠

实例方法详细信息

# cache_keystring

打印出缓存键。 这将为复数模型名称附加不同的值。

如果 new_record? - 将追加 /new 如果没有 - 将追加 /id-updated_at.to_formatted_s(cache_timestamp_format) 没有 updated_at - 将附加 / ID

这通常在 cache() 块内调用

例子:

返回缓存键

document.cache_key

返回:

  • ( string )

    带或不带 updated_at 的string



28
29
30
31
32
# 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