You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fogus edited this page Aug 14, 2012
·
23 revisions
Using core.cache
note: see the page on Including core.cache before you begin this section
For any of the cache implementations, the pattern of usage is as follows:
(require '[clojure.core.cache :as cache])
(defC (cache/fifo-cache-factory {:a1, :b2})
(if (cache/has? C :c)
(cache/hit C :c)
(cache/miss C :c42))
;=> {:a 1, :b 2, :c 42}
(cache/evict C :b)
;=> {:a 1}
Using the has?/hit/miss pattern ensures that the thresholding and eviction logic for each implementation works properly. Avoid this pattern at your own risk.
Builtin cache implementations
core.cache comes with a number of builtin immutable cache implementations, including (click through for specific information):
The core.cache implementations are backed by any map-like object. Additionally, each cache implements the Clojure map behaviors and can therefore serve as special maps or even as backing stores for other cache implementations. For caches taking a limit argument, the eviction policies tend not to apply until the limit has been exceeded.