(defcache FIFOCache [cache q limit]
CacheProtocol
(lookup [_ item]
(get cache item))
(lookup [_ item not-found]
(get cache item not-found))
(has? [_ item]
(contains? cache item))
(hit [this item]
this)
(miss [_ item result]
(let [[kache qq] (let [k (first q)]
(if (>= (count cache) limit)
[(dissoc cache k) (rest q)]
[cache (rest q)]))]
(FIFOCache. (assoc kache item result)
(concat qq [item])
limit)))
(evict [this key]
(if (contains? cache key)
(FIFOCache. (dissoc cache key)
(prune-queue q key)
limit)
this))
(seed [_ base]
(let [{dropping :dropping
q :queue} (describe-layout base limit)]
(FIFOCache. (apply dissoc base dropping)
q
limit)))
Object
(toString [_]
(str cache \, \space (pr-str q))))