views:

9

answers:

1

Hi,

I got the following situation: I have an application configuration in my database which is needed on every request. I don't want to query this configuration on every request because of performance issues.

So what I want is to query the data when the application server (mongrel/webbrick/...) starts and store it permanently until the application server is rebooted or stopped. How could I achieve this?

Thanks for any advice

PS: I'm on Rails3

A: 

Make a request and store it in the cache.

config_model.rb

  def get_config
    Rails.cache.fetch('the_config'){self.the_config}
mark
Hi, I like the initializer idea, do I have access to ActiveRecord already in the initializer? I think storing the data in a constant isn't the way to go because the configuration will be represented as a class.
sled
Sorry, the intializer I don't think would work. But using rails' cache would seem the best solution.
mark
I haven't thought about the cache yet. This is the way to go :) is it possible to initialize and cache this configuration (like ConfigModel::load) in a rails initializer?
sled
During initialization you will have access to the model class but I don't know about the cache, nor any plugins you're using. If you're using capistrano you could run a rake task of the model method on startup.
mark