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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With