ns_memoize - Evaluate a Tcl script and cache the result
A simple wrapper around ns_cache_eval which uses the script to be evaluated as the key to the cached result of evaluating the script. Use this when evaluating the script could take some time.
If the script is not pure, i.e. if it depends on something other than its arguments to compute the result, then you will need to supply an expiry time or explicitly flush the result when the dependency changes.
Evaluate script and args and return the result. The result is cached so that future evaluations of the same script and args will return the cached result without first evaluating the script.
The script result remains valid until the supplied expire time passes, or forever if not specified. The value for -expires can be expressed either as an absolute time in the future (large values are interpreted as seconds since the Unix epoch), or as an offset from the current time.
If two threads execute the same script and args, one will wait for the other to compute the result and store it in the cache. The -timeout option specifies how long to wait.
Flush results from the memoize cache. If a pattern is not given, all results are discarded. If a pattern is given it is treated as a globbing pattern and matched against each script for which there is a cached result in turn, and those that match are discarded.
Note: this may be an expensive operation. First the cache lock is acquired, then all entries in the cache are iterated over in turn matching the script against the globbing pattern. During this period all access to the memoize cache will be blocked.
Return a list of statistics about the effectiveness of the memoize cache. Use this information to help you tune the cache size. See ns_cache_stats for details of the format of this list.
For the next three quarters of an hour, the answer to the "meaning of life" will take no time at all to decide:
set answer [ns_memoize -expires 2520 deep_thought "meaning of life"]
Flush the cache of all thoughts which are deep:
ns_memoize_flush deep_*