Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache values between requests

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)

like image 701
iGEL Avatar asked Mar 05 '12 13:03

iGEL


1 Answers

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)
like image 136
Valentin V Avatar answered Sep 24 '22 14:09

Valentin V