Index: openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-advanced.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-advanced.xml,v diff -u -r1.30 -r1.31 --- openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-advanced.xml 24 Jun 2004 10:44:41 -0000 1.30 +++ openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-advanced.xml 29 Jun 2004 15:50:18 -0000 1.31 @@ -973,6 +973,61 @@ + + Basic Caching + + Based on a post by Dave Bauer. + + + + Implement your proc as my_proc_not_cached + + + Create a version of your proc called my_proc which wraps the non-cached version in the caching mechanism. In this example, my_proc_not_cached takes one argument, -foo, so the wrapper passes that on. + ad_proc my_proc {-foo} { + Get a cached version of my_proc. +} { + return [util_memoize my_proc_not_cached -foo $foo] +} + + + In your code, always call my_proc. 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. + + + + The cached material will of course become obsolete over time. There are two ways to handle this. + + + + Timed Expiration: pass in max_age to util_memoize. If the content is older than max_age, it will be re-generated. + + + + Direct Flushing. In any proc which invalidates the cached content, call util_memoize_flush my_proc_not_cached args. + + + + + If you are correctly flushing the cached value, then it will need to be reloaded. You may wish to pre-load it, so that the loading delay does not impact users. If you have a sequence of pages, you could call the cached proc in advance, to increase the chances that it's loaded and current when the user reaches it. Or, you can call (and discard) it immediately after flushing it. + + + + + Scheduled Procedures + Put this proc in a file /packages/myfirstpackage/tcl/scheduled-init.tcl. Files in /tcl with the -init.tcl ending are sourced on server startup. This one executes my_proc every 60 seconds: + ad_schedule_proc 60 myfirstpackage::my_proc + +This executes once a day, at midnight: + ad_schedule_proc \ + -schedule_proc ns_schedule_daily \ + [list 0 0] \ + myfirstpackage::my_proc + + See ad_schedule_proc for more information. + + + + Future Topics @@ -988,7 +1043,6 @@ How and when to put procedures in a tcl procedure library More on ad_form - data validation, other stuff. (plan to draw from Jon Griffin's doc) - How and when to implement caching partialquery in xql How to use the html/text entry widget to get the "does this look right" confirm page