Вопрос

I am unable to see anything in the cache from the console in either development or production.

For development, I have turned on caching and set it to memory store, in production I use the dalli gem and Memcachier on Heroku.

Every key I try comes back nil.

However, in development, if I put in a binding.pry before somewhere I'm doing a Rails.cache.fetch, I can do a Rails.cache.read there and see something returning, and indeed if so, execution does not go in to the fetch's block.

From the console, if I try Rails.cache.reading the same key that just returned a cached result in the pry breakpoint console, I get nothing. It seems like the console has a separate cache, as if from the console I do Rails.cache.write("whatever", "blah") and Rails.cache.read("whatever"), I get "blah" in return, as expected.

Is there a way to experiment with the cache for a running server from the console?

Это было полезно?

Решение

Change your cache store: the memory store just stores everything in the process's memory, so every instance of the application will have a separate cache. In particular the console won't see anything that is set from the running web application.

You could use the file store (which stores data in temporary files in tmp) or you could also use dalli store locally - memcached is very easy to run.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top