• Publicity: Public Only All

memoize-procs.tcl

Defines a convenient cache mechanism, util_memoize.

Location:
packages/acs-tcl/tcl/memoize-procs.tcl
Created:
2000-10-19
Authors:
Various [acs@arsdigita.com]
Rob Mayoff
Victor Guerra
Gustaf Neumann
CVS Identification:
$Id: memoize-procs.tcl,v 1.18.2.5 2022/12/29 12:54:06 gustafn Exp $

Procedures in this file

Detailed information

util_memoize_flush (public)

 util_memoize_flush script

Forget any cached value for script. If clustering is enabled, flush the caches on all servers in the cluster.

Parameters:
script - The Tcl script whose cached value should be flushed.

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_client_property ad_get_client_property (public) util_memoize_flush util_memoize_flush ad_get_client_property->util_memoize_flush apm::convert_type apm::convert_type (public) apm::convert_type->util_memoize_flush apm_flush_package_id_cache apm_flush_package_id_cache (public) apm_flush_package_id_cache->util_memoize_flush auth::authority::get_flush auth::authority::get_flush (private) auth::authority::get_flush->util_memoize_flush auth::authority::get_id_flush auth::authority::get_id_flush (private) auth::authority::get_id_flush->util_memoize_flush acs::clusterwide acs::clusterwide util_memoize_flush->acs::clusterwide

Testcases:
No testcase defined.

util_memoize_flush_regexp (public)

 util_memoize_flush_regexp [ -log ] expr

Loop through all cached entries, flushing all that match the regular expression that was passed in. It is recommended to use util_memoize_flush_pattern whenever possible, since glob-match is in most cases sufficient and much better performance-wise. the glob match can be better supported by the built-in set of the server.

Switches:
-log
(boolean) (optional)
Whether to log keys checked and flushed (useful for debugging).
Parameters:
expr - The regular expression to match.
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_util_memoize_cache_flush util_memoize_cache_flush (test acs-tcl) util_memoize_flush_regexp util_memoize_flush_regexp test_util_memoize_cache_flush->util_memoize_flush_regexp acs::clusterwide acs::clusterwide util_memoize_flush_regexp->acs::clusterwide ad_cache_returnredirect ad_cache_returnredirect (public) ad_cache_returnredirect->util_memoize_flush_regexp application_data_link::new_from application_data_link::new_from (public) application_data_link::new_from->util_memoize_flush_regexp application_data_link::new_to application_data_link::new_to (public) application_data_link::new_to->util_memoize_flush_regexp auth::authority::get_flush auth::authority::get_flush (private) auth::authority::get_flush->util_memoize_flush_regexp auth::authority::get_id_flush auth::authority::get_id_flush (private) auth::authority::get_id_flush->util_memoize_flush_regexp

Testcases:
util_memoize_cache_flush

util_memoize_initialized_p (public, deprecated)

 util_memoize_initialized_p
Deprecated. Invoking this procedure generates a warning.

Return 1 if the util_memoize cache has been initialized and is ready to be used and 0 otherwise. util_memoize has now a failsafe mechanism when invoked before the cache is there.

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

ad_library {

    Defines a convenient cache mechanism, util_memoize.

    @author Various [acs@arsdigita.com]
    @author Rob Mayoff <mayoff@arsdigita.com>
    @author Victor Guerra
    @author Gustaf Neumann

    @creation-date 2000-10-19
    @cvs-id $Id: memoize-procs.tcl,v 1.18.2.5 2022/12/29 12:54:06 gustafn Exp $
}


ad_proc -deprecated util_memoize_initialized_p {} {
    Return 1 if the util_memoize cache has been initialized
    and is ready to be used and 0 otherwise.

    util_memoize has now a failsafe mechanism when invoked before the
    cache is there.

    @see util_memoize
} -

if { [catch {ns_cache set util_memoize __util_memoize_installed_p 1} error] } {
    # This definition of util_memoize_initialized_p is for loading during bootstrap.

    proc  util_memoize_initialized_p {} {
        #
        # If the cache is not yet created (or some other error is
        # raised) the util_memoize cache is not available.
        #
        if {[catch {ns_cache set util_memoize __util_memoize_installed_p 1} error]} {
            return 0
        }
        #
        # When he call above has success, the cache is initialized, we
        # can rewrite the function in an always succeeding one and
        # return success as well.
        #
        proc ::util_memoize_initialized_p {} {
            return 1
        }
        return 1
    }
} else {
    proc util_memoize_initialized_p {} {
        #
        # This definition of util_memoize_initialized_p is just for
        # reloading, since at that time the cache is always
        # initialized.
        #
        return 1
    }
}


ad_proc -private util_memoize_flush_local {script} {    
    Forget any cached value for <i>script</i> on the local server.
    You probably want to use <code>util_memoize_flush</code> to flush
    the caches on all servers in the cluster, in case clustering is
    enabled.

    @param script The Tcl script whose cached value should be flushed.
} {
    ns_cache flush util_memoize $script
}

ad_proc -public util_memoize_flush {script} {
    Forget any cached value for <i>script</i>.  If clustering is
    enabled, flush the caches on all servers in the cluster.

    @param script The Tcl script whose cached value should be flushed.
} {
    ::acs::clusterwide ns_cache flush util_memoize $script
}

d_proc -private util_memoize_flush_regexp_local {
    -log:boolean
    expr
} {
    Loop through all cached scripts, flushing all that match the
    regular expression that was passed in.

    It is recommended to use util_memoize_flush_pattern whenever
    possible, since glob-match is in most cases sufficient and much
    better performance-wise. the glob match can be better supported by
    the built-in set of the server.

    @see util_memoize_flush_pattern

    @param expr The regular expression to match.
    @param log Whether to log keys checked and flushed (useful for debugging).
} {
    foreach name [ns_cache names util_memoize] {
        if {$log_p} {
            ns_log Debug "util_memoize_flush_regexp: checking $name for $expr"
        }
        if { [regexp $expr $name] } {
            if {$log_p} {
                ns_log Debug "util_memoize_flush_regexp: flushing $name"
            }
            util_memoize_flush $name
        }
    }
}

d_proc -public util_memoize_flush_regexp {
    -log:boolean
    expr
} {
    Loop through all cached entries, flushing all that match the
    regular expression that was passed in.

    It is recommended to use util_memoize_flush_pattern whenever
    possible, since glob-match is in most cases sufficient and much
    better performance-wise. the glob match can be better supported by
    the built-in set of the server.

    @see util_memoize_flush_pattern

    @param expr The regular expression to match.
    @param log Whether to log keys checked and flushed (useful for debugging).
} {
    ::acs::clusterwide util_memoize_flush_regexp_local \
        {*}[expr {$log_p ? "-log" : ""}] \
        $expr
}


# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: