P
Paul
Hello all,
I am trying to cache lookup table values from a database table into a
hash that is stored in a class variable. This will allow me to read and
store the id/descr value pairs from the database one time only after
which I store them in the hash and retrieve them from there.
The problem is the class variable appears to be cleared out each time a
new request comes in to my controller. I am using rails in the
development enrionment but I am hoping this is a Ruby issue. I thought
maybe rails was reloading the class each time a request comes in
because I read this is standard behavior in the development
environment. However, I believe the reloadable? method is supposed to
care of that?
Here is the code from my model class. The code is alwasy going to super
to read from the database. If anyone can steer me straight on this I
would appreciate it!
Thanks in advance.
Paul
class GrammarTenseCode < ActiveRecord::Base
has_many :words
@@cachedDescr = {}
def self.reloadable?
false
end
def descr
if @@cachedDescr[id.to_s] == nil
@@cachedDescr[id.to_s] = super
else
@@cachedDescr[id.to_s]
end
end
end
I am trying to cache lookup table values from a database table into a
hash that is stored in a class variable. This will allow me to read and
store the id/descr value pairs from the database one time only after
which I store them in the hash and retrieve them from there.
The problem is the class variable appears to be cleared out each time a
new request comes in to my controller. I am using rails in the
development enrionment but I am hoping this is a Ruby issue. I thought
maybe rails was reloading the class each time a request comes in
because I read this is standard behavior in the development
environment. However, I believe the reloadable? method is supposed to
care of that?
Here is the code from my model class. The code is alwasy going to super
to read from the database. If anyone can steer me straight on this I
would appreciate it!
Thanks in advance.
Paul
class GrammarTenseCode < ActiveRecord::Base
has_many :words
@@cachedDescr = {}
def self.reloadable?
false
end
def descr
if @@cachedDescr[id.to_s] == nil
@@cachedDescr[id.to_s] = super
else
@@cachedDescr[id.to_s]
end
end
end