Forum OpenACS Development: Caching methods in OpenACS, use which?

My previous post got me thinking a bit about all the different ways that OpenACS supports caching. I recall at least 4 of them:
  • util_memoize.
  • Use an ad hoc nsv or ns_cache.
  • The ad_parameter_cache stuff.
  • Don Baccus's db_* API caching, which I think was merged into CVS in Feb. 2006.
Are there more? (E.g., perhaps XOTcl adds something else?) It'd probably be useful to have a list of all of them in one place. Which methods are now recommended?
Collapse
Posted by Gustaf Neumann on
There is no "offical" recommendation, but i can give a personal one:
- for the casual caching, use util_memoize (it is not the fastest solution, but has e.g. built-in cluster awareness)
- for applications managing a set of related data to be cached, use ns_cache. ns_cache has the advantage that it provides smaller granularity, so the memory bounds can be set for the related data, the statistics are from these etc. (btw, naviserver has improved ns_cache statistics). If it comes to mutex contention, smaller caches are better as well.

xotcl-core and xowiki use ns_cache for these reasons. For cluster-stuff, xotcl-core has ::xo::clusterwide, which can be used for various clusterwide tasks, such as flushing arbitrary ns_caches.

xotcl-core supports as well per-request caching (useful e.g. for multiple permission checks which should be performed only once per connection) which is flushed automatically after the request. This does not need cluster awareness etc. but is certainly not a general replacement for ns_cache.

Collapse
Posted by Don Baccus on
db_* API allows you to specify the ns_cache pool to use, therefore has the benefits of ns_cache in the sense of being able to tune the size of the various pools based on site statistics etc.

I tend to either use query caching directly, or ns_cache eval where I want to cache the result of a series of calculations. I find util_memoize annoying, myself, and I avoid using xotcl in my own custom sites because even fewer people are fluent in xotcl than are fluent in tcl, a downside if a stranger has to come in to work on one of my client sites.