如何在Rails 3.1中获取片段到期日期? [英] How to get fragment expiration date in Rails 3.1?
问题描述
我需要获取缓存条目的过期时间或创建时间。
这是针对:站点地图索引,索引中的每个站点地图都是缓存操作。我想添加
< lastmod>
属性,在我的情况下,这将是缓存条目创建时间。
例如动作缓存:
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测试)一起使用。 $ p> Time.at(Rails.cache.send(:read_entry,'cache / entry / key',{}))。created_at)
read_entry
方法返回 ActiveSupport :: Cache :: Entry
对象(类文档)
I need to get expire or creation time for cache entry.
This is for: sitemap index, each sitemap in index is cached action. I want to add
<lastmod>
attribute, which, in my case, will be cache entry creation time.
For example for action caching:
class ProductsController < ActionController
caches_action :index
def index
@products = Product.all
end
end
I need something like this:
Rails.cache.get(:controller=>'products',:action=>'index').created_at
I found solution, which work with all popular cache stores (tested with redis_store, mem_cache_store, memory_store, file_store).
Time.at(Rails.cache.send(:read_entry,'cache/entry/key',{})).created_at)
read_entry
method returns ActiveSupport::Cache::Entry
object (class documentation)
这篇关于如何在Rails 3.1中获取片段到期日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!