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_caching
is set to true
.
To quote the Rails caching guide ,
caching is disabled by default for development and test, and enabled for production
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.