reseting the cache for cached custom finder calls.

0 views
Skip to first unread message

Jesse Clark

unread,
May 14, 2008, 4:32:54 PM5/14/08
to acts_as_cached
I am using the cached method to cache the results of a custom finder:

@tags = Bookmark.cached( :tags, :ttl => 24.hours, :with => 200 )

The tags finder is really expensive and I want to ensure that when the
ttl expires, users see the old cached data until the tags method
finishes executing and the new results are cached.

How would I go about doing this?

Peter Abrahamsen

unread,
May 14, 2008, 9:49:32 PM5/14/08
to acts_as...@googlegroups.com
Hi Jesse,

I've heard that the best practice is to make the ttl a lot longer than
you expect (or set it not to expire), and then have a cron job set the
new value periodically.

It doesn't sound like a lot of fun to maintain, but probably more fun
than trying to figure out the concurrency issues with any approach
that lives within a web request.

P

Lee Fyock

unread,
May 19, 2008, 2:07:41 PM5/19/08
to acts_as_cached
Or, check out my "avoiding pileups" post at <http://groups.google.com/
group/acts_as_cached/t/fc81947e9e0eb0c3>.

My changes to cache_methods.rb refresh the cache when it's past its
"freshness" time; only one requester refreshes the data.

We use cron tasks for expensive calculations that we know we're going
to need, but for expensive collections that we may or may not need, we
allow one user to take the hit to fill the cache.

Let me know what you think.

Lee
Reply all
Reply to author
Forward
0 new messages