I have an app that heavily relies on dates. There is a moderately expensive calculation that is needed to set these dates, based on the current date. As far as each request is concerned, these dates are constants — they don’t change once created — but they do change throughout the week. The dates are used in both controllers and models.
My problem is this:
- if the dates didn’t change each day, I could set them in config/initializers. But initializers are only evaluated when the server restarts
- if i set the dates in applicationController using before_filter, the dates aren’t available to my models
Any ideas? Am I looking at this all wrong? Thanks.
I think that here you can use Rails caching. Look here and here for more details and examples.
Basicaly, you can write to cache:
and read:
You can use it in whole Rails application (models, views, controllers, …).
You can store any object in cache. Default caching uses memory and is availble for single Rails instance, however you can use different cache storing method.