我需要获取缓存条目的过期或创建时间。
这是给:sitemap index ,索引中的每个站点地图都是缓存的操作。我想添加<lastmod>
属性,在我的情况下,将是缓存条目创建时间。
例如对于 Action 缓存:
class ProductsController < ActionController
caches_action :index
def index
@products = Product.all
end
end
我需要这样的东西:
Rails.cache.get(:controller=>'products',:action=>'index').created_at
最佳答案
我找到了适用于所有流行缓存存储的解决方案(使用 redis_store、mem_cache_store、memory_store、file_store 测试)。
Time.at(Rails.cache.send(:read_entry,'cache/entry/key',{})).created_at)
read_entry
方法返回 ActiveSupport::Cache::Entry
对象(class documentation)
关于ruby-on-rails - 如何在 Rails 3.1 中获取片段到期日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8243846/