Forum OpenACS Q&A: Serverside Caching for time consuming pages/packages

Hi everybody,

is there a way to cache generated pages of a package to prevent the package from recreating the page again in case of future requests when I know that the content wasn't changed in the meantime?

I am using the gatekeeper package for instance and since it rewrites all links to itself, it can take the browser a long time to see the page if the page has many images for instance. Every images is requested from the gatekeeper which first checks its rewrite rules and the forwards the request to the original page.

Thus loading a PHP-page via the gatekeeper takes 15 times longer that loading the page directly (page with 16 images).

Has anyone an idea or knows of a feature of OpenACS that I can use for serverside caching?

Greetings,
Nima

Collapse
Posted by Dave Bauer on
Look at util_memoize.

It is used to cache the result of a tcl procedure in many places in the toolkit. So if you have a tcl procedure that rewrites the page content in gatekeepr and returns a string with the content, you can util_memoize that call.

There is an acs-kernel parameter setting for the size of the cache. It removes old data when the limit is reached. You'll need to do testing to see what a good size is for your application.

Collapse
Posted by Nima Mazloumi on
Thank you Dave. Where can I register the tcl-Proc for this purpose. I found the util_memoize cache itself but there is only a flush feature. Sorry, if the question is too silly.
Collapse
Posted by Dave Bauer on
You'll need two tcl procedures:

my_proc_not_cached

and

my_proc

my_proc will call [util_memoize my_proc_not_cached args]

and your code will always call my_proc.

You can optionally pass in the max_age for the item if you want it to expire.

There will be a seperate cache item for each unique call to my_proc_not_cached so that calls with different arguments are cached seperately. You can flush the cache for each cache key by calling util_memoize_flush my_proc_not_cached args.