简体   繁体   中英

Ruby on rails global cach

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 looking 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]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM