For an AR query like this:
@users = User.find(some_conditions_here)
then @users is an AR array and I want to cache this.
If I do, in one controller call, a
Rails.cache.write('foo',@users)
it doesn’t complain or error out and I can even see a ‘foo’ under /tmp/cache with a non-zero size but a subsequent controller call to
Rails.cache.read('foo')
returns a nil. When I do both the write and read from a Rails console, it works as expected. What is it about doing it via a controller that causes this problem?
This used to work before in Rails 2… what am I missing?
Check that
config.action_controller.perform_cachingis set totrue.To quote the Rails caching guide,