ttl
function
clojure.core.memoize/ttl
(ttl [f] [f base] [f tkey threshold] [f base key threshold])Unlike many of the other core.memo memoization functions,
`memo-ttl`'s cache policy is time-based rather than algorithmic
or explicit. When memoizing a function using `memo-ttl` you
should provide a **T**ime **T**o **L**ive parameter in
milliseconds.
(require '[clojure.core.memoize :as memo])
(def id (memo/ttl identity :ttl/threshold 5000))
(id 42)
(snapshot id)
;=> {[42] 42}
... wait 5 seconds ...
(id 43)
(snapshot id)
;=> {[43] 43}
The expired cache entries will be removed on each cache **miss**.
Examples
No examples yet. Be the first to add one!