开发者

Ruby on rails global cach

开发者 https://www.devze.com 2023-03-13 17:49 出处:网络
I need some global variable on my server that will always be there Is there a built in way to use some global cache on a rails server?

I need some global variable on my server that will always be there Is there a built in way to use some global cache on a rails server?

I'm lo开发者_如何转开发oking for a query cache that will last for an hour.

Is it recommended?


I always put variables I want to access everywhere into the environments/{production,development,..}.rb files, depending of the environment. If you want some fast datastore, which needs to store some more complex data, I would suggest redis. If redis is to heavy for your use case you can also use the Rails Caching.


you can always add an app specific yaml file that you load from a file in initializers

in initializers:

raw_config = File.read("#{Rails.root}/config/app_config.yml")

APP_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys

then you can access APP_CONFIG from anywhere in your app APP_CONFIG[:some_var]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号