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):
%3 test_util_memoize_cache util_memoize_cache (test acs-tcl) util_memoize util_memoize test_util_memoize_cache->util_memoize test_util_memoize_cache_flush util_memoize_cache_flush (test acs-tcl) test_util_memoize_cache_flush->util_memoize test_util_memoize_cache_script util_memoize_cache_script (test acs-tcl) test_util_memoize_cache_script->util_memoize Class ::xowiki::includelet::random-form-page Class ::xowiki::includelet::random-form-page (public) Class ::xowiki::includelet::random-form-page->util_memoize acs::root_of_host_noncached acs::root_of_host_noncached (private) acs::root_of_host_noncached->util_memoize acs_lookup_magic_object acs_lookup_magic_object (private, deprecated) acs_lookup_magic_object->util_memoize acs_object::package_id acs_object::package_id (public) acs_object::package_id->util_memoize acs_object_type::get_table_name acs_object_type::get_table_name (public) acs_object_type::get_table_name->util_memoize

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
[ hide source ] | [ make this the default ]
Show another procedure: