Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fragment expiration date in Rails 3.1?

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
like image 378
rogal111 Avatar asked Feb 23 '23 08:02

rogal111


1 Answers

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)

like image 57
rogal111 Avatar answered Feb 24 '23 22:02

rogal111