I have a problem with my Ruby on rails application. The Ruby on Rails Cache in ApplicationController. The data can't get, but it exists.
class ApplicationController < ActionController::Base
before_filter :init
def init
@setting = Rails.cache.read("data/setting")
if not @setting
@setting = Setting.find_create
Rails.cache.write("data/setting",@setting)
end
end
end
Development.log show this:
Cache read: data/setting
Setting Load (0.5ms) SELECT * FROM > "settings" LIMIT 1
Cache write: data/setting
Why is this happening?
If you are running your app in development mode, it's likely that caching is turned off. Check your config/development.rb file for the following:
config.action_controller.perform_caching = false
To test your caching you can either change this value to true, or run in a different environment where caching is turned on. I often create an environment development_as_production, pointing at the development db, but with my production.rb settings.
I am Json, I was changed the name.
But the development environment setting current is:
config.action_controller.perform_caching = true
The perform_caching was trun on! The others caches can working. only this cache didn't working (It's in the ApplicationController).
@setting = Rails.cache.read("data/setting")
if not @setting
@setting = Setting.find_create
Rails.cache.write("data/setting",@setting)
end
Why? Is Rails.cache.read can't working in the ApplicationController?
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.