Let’s say I’ve got a forum app where there are Topic objects and Post
objects.
Each Post has a topic_id column and a parent_id column.
Each topic has a root_post that, minus error-checking, etc., boils down
to:
def root_post
Post.find(
:first,
:conditions => “topic_id = #{self.id} and parent_id IS NULL”
)
end
Where can I store the root_post so that I don’t have to go to the DB
every time I need it?
This just has to be brain dead simple, but I haven’t found the answer
yet.
If I put any ActiveRecord into the session, I get marshalling problems
when the session is saved to the DB. Perhaps there is a place to store
things in the session that don’t get saved? Or a more general
app-level caching mechanism?
If I put any ActiveRecord into the session, I get marshalling problems
when the session is saved to the DB. Perhaps there is a place to store
things in the session that don’t get saved? Or a more general
app-level caching mechanism?
The only built-in caching deals with caching the rendered output.
Folks tend to use something like memcache to cache the actual models
though. Look at acts_as_cached and cached_model: