Duplicates LRU Cache functionality from clojure.core.cache. Duplicated because that cache is not available for ClojureScript and the namespace includes JVM specific functionality.
Duplicates LRU Cache functionality from clojure.core.cache. Duplicated because that cache is not available for ClojureScript and the namespace includes JVM specific functionality.
This is the protocol describing the basic cache capability.
This is the protocol describing the basic cache capability.
(evict cache e)
Removes an entry from the cache
Removes an entry from the cache
(has? cache e)
Checks if the cache contains a value associated with e
Checks if the cache contains a value associated with `e`
(hit cache e)
Is meant to be called if the cache is determined to contain a value associated with e
Is meant to be called if the cache is determined to contain a value associated with `e`
(lookup cache e)
(lookup cache e not-found)
Retrieve the value associated with e
if it exists, else nil
in
the 2-arg case. Retrieve the value associated with e
if it exists,
else not-found
in the 3-arg case.
Retrieve the value associated with `e` if it exists, else `nil` in the 2-arg case. Retrieve the value associated with `e` if it exists, else `not-found` in the 3-arg case.
(miss cache e ret)
Is meant to be called if the cache is determined to not contain a value associated with e
Is meant to be called if the cache is determined to **not** contain a value associated with `e`
(seed cache base)
Is used to signal that the cache should be created with a seed. The contract is that said cache should return an instance of its own type.
Is used to signal that the cache should be created with a seed. The contract is that said cache should return an instance of its own type.
(defcache type-name fields & specifics)
Defines common functionality across cache types. Not needed for this single LRU cache, but this macro is staying in case other caches are also ported. A similar macro can be used in ClojureScript, but the macro needs to be in the same namespace at the CacheProtocol, and while this works it also causes warnings when the :clj protocol is parsed during compilation.
Defines common functionality across cache types. Not needed for this single LRU cache, but this macro is staying in case other caches are also ported. A similar macro can be used in ClojureScript, but the macro needs to be in the same namespace at the CacheProtocol, and while this works it also causes warnings when the :clj protocol is parsed during compilation.
(lru-cache-factory base & {threshold :threshold :or {threshold 32}})
Returns an LRU cache with the cache and usage-table initialied to base
--
each entry is initialized with the same usage value.
This function takes an optional :threshold
argument that defines the maximum number
of elements in the cache before the LRU semantics apply (default is 32).
Returns an LRU cache with the cache and usage-table initialied to `base` -- each entry is initialized with the same usage value. This function takes an optional `:threshold` argument that defines the maximum number of elements in the cache before the LRU semantics apply (default is 32).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close