Forum OpenACS Development: Caching: db_cache_pool vs. util_memoize

Don, as you mentioned that you are using the db_cache_pool a lot maybe you can quickly describe in what situations you are using it and how?

I have the slight feeling that a lot of code where we are using util_memoize for at the moment could be refactored using db_cache_pool, but I would like to write up a small guideline on when to do chaching and which kind of caching, so hopefully you (and others) can help out

Posted by Don Baccus on
Personally I'd recommend using the db cache facility, or ns_cache directly (possibly in a proc depending on circumstances), rather than util_memoize. Long-term, I'd get rid of util_memoize entirely.

Use the db cache feature to cache query results, use ns_cache if you want to cache the result of something computed in Tcl.

The tricky bit with the db cache pool stuff is to construct a useful key for maintaining cache contents.

But that's true with util_memoize as well, cache coherency is a problem no matter what one does.

Posted by Malte Sussdorff on
Reading up on that, util_memoize has the benefit that it works across clusters. Does the db_cache support that as well?

Additionally I am wondering, especially due to the cluster situation, if we should not have a wrapper for ns_cache, which allows us to flush the cache across the cluster if needed.

My assumption is that we will probably need a wrapper for ns_cache, which behaves similar to util_memoize with regards to clusters (and the flush-memoized-statement.tcl file), but offers more functionality and if it is only the name of the cache to use.

Last but not least I am wondering where we should provide the functionality to set the size of the caches? At the moment this is done in the Kernel parameters, so should each new cache have it's own setting there? How about default timeouts?