acs::disk_cache_eval (public)

 acs::disk_cache_eval -call call -key key -id id

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

Evaluate an expression. When the acs-tcl.DiskCache parameter is set, cache the result on the disk. If a cache already exists, return the cached value.

Switches:
-call
(required)
a Tcl snippet executed in the caller scope.
-key
(required)
a key used to name the directory where the disk cache will be stored.
-id
(required)
an id used to name the file where the disk cache will be stored. The name will also depend on a hash of the actual snippet.

Partial Call Graph (max 5 caller/called nodes):
%3 test_disk_cache disk_cache (test acs-tcl) acs::disk_cache_eval acs::disk_cache_eval test_disk_cache->acs::disk_cache_eval ad_file ad_file (public) acs::disk_cache_eval->ad_file ad_tmpdir ad_tmpdir (public) acs::disk_cache_eval->ad_tmpdir parameter::get_from_package_key parameter::get_from_package_key (public) acs::disk_cache_eval->parameter::get_from_package_key template::util::read_file template::util::read_file (public) acs::disk_cache_eval->template::util::read_file template::util::write_file template::util::write_file (public) acs::disk_cache_eval->template::util::write_file

Testcases:
disk_cache
Source code:
        set cache [::parameter::get_from_package_key  -package_key acs-tcl  -parameter DiskCache  -default 1]
        if {$cache} {
            set hash [ns_sha1 $call]
            set dir [ad_tmpdir]/oacs-cache/$key
            set file_name $dir/$id-$hash
            if {![ad_file isdirectory $dir]} {
                file mkdir $dir
            }
            ns_mutex eval [nsv_get ad_disk_cache mutex] {
                if {[ad_file readable $file_name]} {
                    set result [template::util::read_file $file_name]
                } else {
                    set result [uplevel $call]
                    template::util::write_file $file_name $result
                }
            }
        } else {
            set result [uplevel $call]
        }
        return $result
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: