acs::LockfreeCache method eval (public)

 <instance of acs::LockfreeCache[i]> eval -key key  \
    [ -no_cache no_cache ] [ -no_empty ] \
    [ -from_cache_indicator from_cache_indicator ] cmd

Defined in packages/acs-tcl/tcl/acs-cache-procs.tcl

Use the "prefix" to determine whether the cache is per-thread or per-request.

Switches:
-key (required)
key for caching, should start with package-key and a dot to avoid name clashes
-no_cache (optional)
list of returned values that should not be cached
-no_empty (optional, defaults to "false")
don't cache empty values. This flag is deprecated, one should use the no_cache flag instead.
-from_cache_indicator (optional)
variable name to indicate whether the returned value was from cache or not
Parameters:
cmd (required)
command to be executed.
Returns:
return the last value set (don't use "return").

Testcases:
No testcase defined.
Source code:
if {[info exists from_cache_indicator]} {
    :upvar $from_cache_indicator from_cache
}

#if {![info exists ${:prefix}]} {
#    ns_log notice "### exists ${:prefix} ==> 0"
#} else {
#    ns_log notice "### [list dict exists [set ${:prefix}] $key] ==>  [dict exists [set ${:prefix}] $key]"
#}

if {![info exists ${:prefix}] || ![dict exists [set ${:prefix}$key]} {
    #ns_log notice "### call cmd <$cmd>"
    set from_cache 0
    set value [:uplevel $cmd]
    if {$no_empty} {
        ad_log warning "no_empty flag is deprecated and will be dropped in the future."
        lappend no_cache ""
    }
    if {[info exists no_cache] && $value in $no_cache} {
        #ns_log notice "### cache eval $key returns <$value> without caching"
        return $value
    }
    #if {$value eq "0"} {
    #    ns_log notice "### cache eval $key returns <$value> with caching"
    #}
    dict set ${:prefix} $key $value
    #ns_log notice "### [list dict set ${:prefix} $key $value]"
} else {
    set from_cache 1
    set value [dict get [set ${:prefix}$key]
}
#ns_log notice "### will return [list dict get ${:prefix} $key]"
return $value
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: