util_memoize (public)
util_memoize script [ max_age ]
Defined in packages/acs-tcl/tcl/memoize-procs-naviserver.tcl
If script has been executed before, return the value it returned last time, unless it was more than max_age seconds ago.
Otherwise, evaluate script and cache and return the result.
Note: script is not evaluated with
uplevel
.
- Parameters:
- script - A Tcl script whose value should be memoized. May be best to pass this as a list, e.g.
[list someproc $arg1 $arg2]
.
max_age (optional) - The maximum age in seconds for the cached value of script. If the cached value is older than max_age seconds, script will be re-executed.
- Returns:
- The possibly-cached value returned by script.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util_memoize_cache, util_memoize_cache_script, util_memoize_cache_flush
Source code: # # When util_memoize is called before the cache is created don't # raise an error but eval without caching. # # The AOLserver version of the proc says "no uplevel", so do not # uplevel here either. # # https://github.com/openacs/openacs-core/blob/master/packages/acs-tcl/tcl/memoize-procs-aolserver.tcl#L16 # if {[ns_cache_exists util_memoize]} { if {$max_age ne ""} { set max_age "-expires $max_age" } ns_cache_eval {*}$max_age -- util_memoize $script [list eval $script] } else { eval $script }XQL Not present: Generic, PostgreSQL, Oracle