I need to load some read-only lookup data from the database into memory
for fast access (i.e. caching). What's the best way to cache data in
memory in Rails apps? For example, should I use global, class or
instance variables? I realize each controller in my cluster will have
it's own copy, which is fine.
I need to load some read-only lookup data from the database into
memory
for fast access (i.e. caching). What's the best way to cache data in
memory in Rails apps? For example, should I use global, class or
instance variables? I realize each controller in my cluster will have
it's own copy, which is fine.
Doesn't need to be anything cleverer than a class variable (or a class
instance variable).
Has anyone used Rails.cache.write / read? I wonder how good of a
solution that is.
I haven't used it, but it is a different beast. It is something that
is shared across all the processes in your cluster, so it's doing more
which implies that it will have more overhead then just reading an
instance variable out of something. It also uses Marshal.dump to dump
the objects it stores which can introduces some complexities)
It would be best to use the rails built in method because if something
comes along like a newer or alternative method of caching you only
have to modify a few bits of your code or even none at all. Just
update your Rails or gems or whatever. Your caching code doesn't
require any modification.