rog*_*111 3 caching ruby-on-rails ruby-on-rails-3
我需要获得缓存条目的过期或创建时间.
这适用于:sitemap索引,索引中的每个站点地图都是缓存操作.我想添加
<lastmod>属性,在我的情况下,将是缓存条目创建时间.
例如,对于动作缓存:
class ProductsController < ActionController
caches_action :index
def index
@products = Product.all
end
end
Run Code Online (Sandbox Code Playgroud)
我需要这样的东西:
Rails.cache.get(:controller=>'products',:action=>'index').created_at
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案,它适用于所有流行的缓存存储(使用redis_store,mem_cache_store,memory_store,file_store测试).
Time.at(Rails.cache.send(:read_entry,'cache/entry/key',{})).created_at)
Run Code Online (Sandbox Code Playgroud)
read_entry方法返回ActiveSupport::Cache::Entry对象(类文档)
| 归档时间: |
|
| 查看次数: |
1528 次 |
| 最近记录: |