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]
精彩评论