function-cache

API Reference

function-cache

A Simple Caching Layer for functions

FUNCTION-CACHE

A simple caching layer for functions
  • Generic-Function CLEAR-CACHE (cache &optional args)
    Clears a given cache
  • Generic-Function PURGE-CACHE (cache)
    A function that will remove expired entries from the cache, allowing them to be garbage collected
  • Generic-Function GET-CACHED-VALUE (cache cache-key)
    returns the result-values-list and at what time it was cached
  • Generic-Function (setf GET-CACHED-VALUE) (new cache cache-key)
    Set the cached value for the cache key
  • Method (setf GET-CACHED-VALUE) (new cache cache-key)
  • Method (setf GET-CACHED-VALUE) (new cache cache-key)
  • Method (setf GET-CACHED-VALUE) (new cache cache-key)
  • Generic-Function AT-CACHE-CAPACITY? (cache)
    is the cache full?
  • Method AT-CACHE-CAPACITY? (cache)
  • Method AT-CACHE-CAPACITY? (cache)
  • Method AT-CACHE-CAPACITY? (cache)
  • Generic-Function REDUCE-CACHED-SET (cache n)
    evict n items from the cache
  • Generic-Function CACHED-RESULTS-COUNT (cache)
    A function to compute the number of results that have been cached. DOES NOT CHECK to see if the entries are expired
  • Method CACHED-RESULTS-COUNT ((res hash-table))
  • Method CACHED-RESULTS-COUNT ((res hash-table))
  • Method CACHED-RESULTS-COUNT ((res hash-table))
  • Method CACHED-RESULTS-COUNT ((res list))
  • Method CACHED-RESULTS-COUNT ((res list))
  • Method CACHED-RESULTS-COUNT ((res list))
  • Generic-Function DEFCACHED-HASHKEY (thing)
    Turns a list of arguments into a valid cache-key (usually a tree of primatives)
  • Method DEFCACHED-HASHKEY ((thing t))
  • Method DEFCACHED-HASHKEY ((thing t))
  • Method DEFCACHED-HASHKEY ((thing t))
  • Class CACHE-CAPACITY-MIXIN
    CAPACITY   Accessor: CAPACITY
    The maximum number of objects cached, when we hit this we will reduce the number of cached entries by reduce-by-ratio
    REDUCE-BY-RATIO   Accessor: REDUCE-BY-RATIO
    Remove the oldest reduce-by-ratio entries (eg: .2 or 20%)
  • Method AT-CACHE-CAPACITY? ((cache cache-capacity-mixin))
  • Method (setf GET-CACHED-VALUE) (new (cache cache-capacity-mixin) cache-key)
  • Class METERED-MIXIN
    adds some recording for caches hits/misses
    HITS   Accessor: HITS
    how many cache hits
    MISSES   Accessor: MISSES
    how many cache hits
  • Function ACCESSES (cache)
    how many total accesses this cache has seen
  • Function HIT-RATIO (cache)
  • Method GET-CACHED-VALUE ((cache metered-mixin) cache-key)
  • Generic-Function RESET-COUNTERS (cache)
    When we clear the full cache, reset the counters
  • Method RESET-COUNTERS ((cache metered-mixin))
  • Method RESET-COUNTERS ((cache metered-mixin))
  • Method RESET-COUNTERS ((cache metered-mixin))
  • Method RESET-COUNTERS ((cache symbol))
  • Method RESET-COUNTERS ((cache symbol))
  • Method RESET-COUNTERS ((cache symbol))
  • Method CACHED-RESULTS ((cache function-cache))
    Coerce the refernce to the results into something we can use
  • Method CLEAR-CACHE ((cache function-cache) &optional args)
  • Method PURGE-CACHE ((cache function-cache))
  • Generic-Function COMPUTE-CACHE-KEY (cache thing)
    Used to assemble cache keys for function-cache objects
  • Method COMPUTE-CACHE-KEY ((cache function-cache) thing)
  • Method COMPUTE-CACHE-KEY ((cache function-cache) thing)
  • Method COMPUTE-CACHE-KEY ((cache function-cache) thing)
  • Variable *BYPASS-CACHE*
    nil
    if non-nil, skip any kind of caching
  • Class THUNK-CACHE  (FUNCTION-CACHE)
    a cache optimized for functions of no arguments (uses a cons for caching)
    No slots.
  • Method GET-CACHED-VALUE ((cache thunk-cache) cache-key)
  • Method CACHED-RESULTS-COUNT ((cache thunk-cache))
  • Method PURGE-CACHE ((cache thunk-cache))
  • Class SINGLE-CELL-FUNCTION-CACHE  (FUNCTION-CACHE)
    a cache that stores only the most recent result of running the body
    TEST   Accessor: TEST
  • Method CACHED-RESULTS-COUNT ((cache single-cell-function-cache))
  • Method GET-CACHED-VALUE ((cache single-cell-function-cache) cache-key)
  • Method PURGE-CACHE ((cache single-cell-function-cache))
  • Class HASH-TABLE-FUNCTION-CACHE  (FUNCTION-CACHE)
    a function cache that uses a hash-table to store results
    HASH-INIT-ARGS   Accessor: HASH-INIT-ARGS
  • Method CACHED-RESULTS-COUNT ((cache hash-table-function-cache) &aux (cached (cached-results cache)))
  • Method GET-CACHED-VALUE ((cache hash-table-function-cache) cache-key)
  • Generic-Function PARTIAL-ARGUMENT-MATCH? (cache cached-key to-match &key test)
    Trys to see if the cache-key matches the to-match partial key passed in. The basic implementation is to go through the cache-keys and match in order, skipping to-match component that is function-cache:dont-care
  • Method PARTIAL-ARGUMENT-MATCH? ((cache hash-table-function-cache) cached-key to-match &key (test (let ((hash (cached-results cache))) (when hash (hash-table-test hash)))))
  • Method PARTIAL-ARGUMENT-MATCH? ((cache hash-table-function-cache) cached-key to-match &key (test (let ((hash (cached-results cache))) (when hash (hash-table-test hash)))))
  • Method PARTIAL-ARGUMENT-MATCH? ((cache hash-table-function-cache) cached-key to-match &key (test (let ((hash (cached-results cache))) (when hash (hash-table-test hash)))))
  • Generic-Function CLEAR-CACHE-PARTIAL-ARGUMENTS (cache to-match)
    This function will go through the cached-results removing keys that partially match the to-match list. This is used to clear the cache of shared? caches, but is also useful in other cases, where we need to clear cache for some subset of the arguments (eg: a cached funcall might wish to clear the cache of a specific funcalled function). Matches arguments for those provided. Anything not provided is considered function-cache:dont-care. Anything specified as function-cache:dont-care is not used to determine if there is a match
  • Method CLEAR-CACHE-PARTIAL-ARGUMENTS ((cache hash-table-function-cache) to-match)
  • Method CLEAR-CACHE-PARTIAL-ARGUMENTS ((cache hash-table-function-cache) to-match)
  • Method CLEAR-CACHE-PARTIAL-ARGUMENTS ((cache hash-table-function-cache) to-match)
  • Method CLEAR-CACHE ((cache hash-table-function-cache) &optional (args nil args-input?) &aux (name (name cache)) (hash (cached-results cache)) (shared-results? (shared-results? cache)))
  • Method PURGE-CACHE ((cache hash-table-function-cache) &aux (hash (cached-results cache)))
  • Method REDUCE-CACHED-SET ((cache hash-table-function-cache) n)
  • Class HASH-TABLE-FUNCTION-CACHE-WITH-CAPACITY  (CACHE-CAPACITY-MIXIN, HASH-TABLE-FUNCTION-CACHE)
    a function cache that uses a hash-table to store results with a max capacity
    No slots.
  • Method GET-CACHED-VALUE ((cache ordered-cache-mixin) cache-key)
  • Method (setf GET-CACHED-VALUE) (new (cache ordered-cache-mixin) cache-key)
  • Method CLEAR-CACHE-PARTIAL-ARGUMENTS ((cache ordered-cache-mixin) to-match)
  • Method CLEAR-CACHE ((cache ordered-cache-mixin) &optional args)
  • Method PURGE-CACHE ((cache ordered-cache-mixin))
  • Class LRU-CACHE  (ORDERED-CACHE-MIXIN, HASH-TABLE-FUNCTION-CACHE)
    LRU cache backed by a hash-table. Maintains capacity by removing least recently used cached values.
    No slots.
  • Method REDUCE-CACHED-SET ((cache lru-cache) n)
  • Class MRU-CACHE  (ORDERED-CACHE-MIXIN, HASH-TABLE-FUNCTION-CACHE)
    MRU cache backed by a hash-table. Maintains capacity by removing the most recently used cached value.s
    No slots.
  • Method REDUCE-CACHED-SET ((cache mru-cache) n)
  • Variable *CACHE-NAMES*
    nil
    A list of all function-caches
  • Variable *DEFAULT-CACHE-CLASS*
    'function-cache::metered-hash-table-cache
    cache class to use if unspecified and thunk is not applicable
  • Function FIND-FUNCTION-CACHE-FOR-NAME (cache-name)
    given a name get the cache object associated with it
  • Method CLEAR-CACHE ((cache-name null) &optional args)
  • Method CLEAR-CACHE ((cache-name symbol) &optional (args nil args-input?))
  • Method PURGE-CACHE ((cache-name symbol))
  • Function CLEAR-CACHE-ALL-FUNCTION-CACHES (&optional package)
    Clear all the packages we know about. If there is a package mentioned, clear only those caches whose names are in that package
  • Function PURGE-ALL-CACHES (&optional package)
    Call purge on all matching cache objects. If package is provided, purge only caches located within that package
  • Macro DEFCACHED (symbol lambda-list &body body)
    Creates a cached function named SYMBOL and a cache object named *{FN-NAME}-CACHE* SYMBOL can also be a list (FN-NAME &rest CACHE-INIT-ARGS &key CACHE-CLASS TABLE TIMEOUT SHARED-RESULTS?) TABLE - a shared cache-store to use, usually a hash-table, a function that returns a hashtable, or a symbol whose value is a hash-table TIMEOUT - how long entries in the cache should be considered valid for CACHE-CLASS - controls what cache class will be instantiated (uses default-cache-class if not provided) SHARED-RESULTS? - do we expect that we are sharing cache space with other things defaults to t if TABLE is provided CACHE-INIT-ARGS - any other args that should be passed to the cache

function-cache-clsql

A Simple Caching Layer for functions

No packages.