Skip to content

Commit

Permalink
CCACHE-7: Adds eviction method to FIFOCache
Browse files Browse the repository at this point in the history
  • Loading branch information
fogus committed Dec 9, 2011
1 parent 7be1589 commit 094363f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/main/clojure/clojure/core/cache.clj
Expand Up @@ -113,6 +113,10 @@
(recur (dissoc m (first ks)) (next ks))
m))

(defn- prune-queue [q ks]
(into clojure.lang.PersistentQueue/EMPTY
(filter (complement (set ks)) q)))

(defcache FIFOCache [cache q limit]
CacheProtocol
(lookup [_ item]
Expand All @@ -126,9 +130,13 @@
(FIFOCache. (-> cache (dissoc k) (assoc item result))
(-> q pop (conj item))
limit)))
(evict [_ key]
(evict [this key]
(let [v (get cache key ::miss)]
nil))
(if (= v ::miss)
this
(FIFOCache. (dissoc cache key)
(prune-queue q [key])
limit))))
(seed [_ base]
(let [{dropping :dropping
q :queue} (describe-layout base limit)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/clojure/clojure/core/cache/tests.clj
Expand Up @@ -101,7 +101,7 @@
(do-ilookup-tests (FIFOCache. small-map clojure.lang.PersistentQueue/EMPTY 2)))
(testing "assoc and dissoc for FifoCache"
(do-assoc (FIFOCache. {} clojure.lang.PersistentQueue/EMPTY 2))
#_(do-dissoc (FIFOCache. {:a 1 :b 2} clojure.lang.PersistentQueue/EMPTY 2)))
(do-dissoc (FIFOCache. {:a 1 :b 2} clojure.lang.PersistentQueue/EMPTY 2)))
(testing "that get and cascading gets work for FifoCache"
(do-getting (FIFOCache. big-map clojure.lang.PersistentQueue/EMPTY 2)))
(testing "that finding works for FifoCache"
Expand Down

0 comments on commit 094363f

Please sign in to comment.