Forum OpenACS Q&A: Re: How do I cache a big database request?

Collapse
Posted by Don Baccus on
I'm adding the db_* caching API used at Greenpeace and the Berklee School of Music to contrib/misc in the OpenACS 4 tree.

This allows you to cache a multirow like this:

db_multirow -cache foo foo {query}

The only caveat is that as written you must use "$var" rather than the bindvar approach normally used (":var") for any Tcl variable in the query that change the result.  This is because the query string itself (after Tcl vars are replaced with their values) is used as the cache key.

It's this kludgey approach that makes it not quite ready for prime time in a general way, but it has worked really well for GP and Berklee and is extremely simple to use.

It has a sledge-hammer approach to flushing - call db_flush and the given cache pool is flushed of all entries.

For a general caching db API we need a better way of specifying cache keys and a less obnoxious approach towards kill cache entries.  This is why I'm putting it in contrib/misc for now.

But you may find it useful as is in the short term!