- Publicity: Public Only All
memoize-procs-naviserver.tcl
Defines a convenient cache mechanism, util_memoize.
- Location:
- packages/acs-tcl/tcl/memoize-procs-naviserver.tcl
- Created:
- 2000-10-19
- Authors:
- Various [acs@arsdigita.com]
- Rob Mayoff
- Victor Guerra
- Gustaf Neumann
- CVS Identification:
$Id: memoize-procs-naviserver.tcl,v 1.11 2024/09/11 06:15:48 gustafn Exp $
Procedures in this file
- util_memoize (public)
- util_memoize_cached_p (public)
- util_memoize_flush_pattern (public)
- util_memoize_seed (public)
Detailed information
util_memoize (public)
util_memoize script [ max_age ]
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 (required)
- 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
util_memoize_cached_p (public)
util_memoize_cached_p script [ max_age ]
Check whether script's value has been cached, and whether it was cached no more than max_age seconds ago.
- Parameters:
- script (required)
- A Tcl script.
- max_age (optional)
- Maximum age of cached value in seconds.
- Returns:
- Boolean value.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util_memoize_cache, util_memoize_cache_script, util_memoize_cache_flush
util_memoize_flush_pattern (public)
util_memoize_flush_pattern [ -log ] pattern
Loop through all cached entries, flushing all that match the pattern that was passed in.
- Switches:
- -log (optional, boolean)
- Whether to log keys checked and flushed (useful for debugging).
- Parameters:
- pattern (required)
- Match pattern (glob pattern like in 'string match $pattern ...').
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- group_localization, acs_subsite_expose_bug_775, acs_subsite_check_composite_group
util_memoize_seed (public)
util_memoize_seed script value [ max_age ]
Pretend
util_memoize
was called with script and it returned value. Cache value, replacing any previous cache entry for script.If clustering is enabled, this command flushes script's value from the caches on all servers in the cluster before storing the new value. The new value is only stored in the local cache.
- Parameters:
- script (required)
- A Tcl script that presumably would return value.
- value (required)
- The value to cache for script.
- max_age (optional)
- Not used.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.