I have a (tableless) options model, which reads it's values from a yaml file. The yaml is part of the project, so if I keep my workflow, the options cannot change without redeploying and restarting the entire application. So it's not necessary to read and parse the file on every request. Because of this, I would like to cache the values between the requests.
So far, I've load the options into a class variable (@@options
), but I'm not sure, if there is a better way.
(Do not say the session. These options aren't session variables, since they apply to all requests from all clients. Also I'm using the CookieStore)
You can use Rails cache store.
To write to the cache:
Rails.cache.write(key, value)
To read from the cache:
Rails.cache.read(key)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With