Class ::acs::LockfreeCache

::acs::LockfreeCache[i] create ... \
           [ -prefix prefix ]

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
::nx::Class create ::acs::LockfreeCache \
     -superclass ::nx::Object

Methods (to be applied on instances)

  • eval (scripted)

    if {[info exists from_cache_indicator]} {
        :upvar $from_cache_indicator from_cache
    }
    
    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
  • flush (scripted)

    if {[info exists ${:prefix}]} {
        if {$pattern eq "*"} {
            ns_log notice "### dict flush ${:prefix} <$pattern>"
            unset -nocomplain ${:prefix}
        } elseif {[string first "*" $pattern] != -1} {
            #
            # A real pattern with wild-card was provided.
            #
            set keys [dict keys [set ${:prefix}$pattern]
            ns_log notice "### dict flush ${:prefix} <$pattern> -> [llength $keys]"
            foreach key $keys {
                dict unset ${:prefix} $key
            }
        } elseif [dict exists [set ${:prefix}$pattern] {
            #
            # A "pattern" without a wildcard was provided
            #
            dict unset ${:prefix} $pattern
        }
    }
  • get (scripted)

    if {[info exists ${:prefix}] && [dict exists [set ${:prefix}$key]} {
        :upvar $var value
        set value [dict get [set ${:prefix}$key]
        return 1
    }
    return 0