dlu
dlu

Reputation: 791

Way to examine contents of Rails cache?

I'm trying to debug stale entries in a cached view in a Rails (5.0.0.beta2) running on Heroku. I'd like to look at the entries in the cache to confirm that they are named the way that I expect and are getting expired when they should.

Is there any way to do this? I found this question, HOW do i see content of rails cache, which suggests Rails.cache.read("your_key"). So, using bin/rails c (on Heroku) I tried:

Rails.cache.read(User.find(19).cache_key) => nil

Where 19 is the :id of one of the users for whom I'm seeing stale data. This has me kind of stumped...

If I try:

User.find(19).cache_key => "users/19-20160316151228266421"

But when a cache entry is supposedly expired the log line looks like:

Expire fragment views/users/19-20160316151228266421 (0.2ms)

So I tried doing a Rails.cache.read on that path, this also returned nil – I also tried doing the same with a user that had not be expired, and got nil again.

I'm wondering if that difference in path signals a problem, or if there is a way to see the path of the key that is created (I've been assuming that it matches at least the part after the slash).

Upvotes: 5

Views: 7525

Answers (1)

Allison
Allison

Reputation: 2333

Cache has the following instance variables:

[:@options, :@data, :@key_access, :@max_size, :@max_prune_time, :@cache_size, :@monitor, :@pruning]

You can examine the data with:

Rails.cache.instance_variable_get(:@data)

Upvotes: 9

Related Questions