Permalink
Browse files

CCACHE-10: Implementing evict for LUCache. Very similar to LRU version

  • Loading branch information...
1 parent 375ed14 commit ca4587bdbdca2728b191bf98472a778231250e61 @fogus fogus committed Dec 12, 2011
Showing with 10 additions and 3 deletions.
  1. +8 −1 src/main/clojure/clojure/core/cache.clj
  2. +2 −2 src/test/clojure/clojure/core/cache/tests.clj
@@ -244,7 +244,14 @@
limit))
(LUCache. (assoc cache item result) ;; no change case
(assoc lu item 0)
- limit)))
+ limit)))
+ (evict [this key]
+ (let [v (get cache key ::miss)]
+ (if (= v ::miss)
+ this
+ (LUCache. (dissoc cache key)
+ (dissoc lu key)
+ limit))))
(seed [_ base]
(LUCache. base
(into {} (for [x (range (- limit) 0)] [x x]))
@@ -128,9 +128,9 @@
(deftest test-lu-cache-ilookup
(testing "that the LUCache can lookup via keywords"
(do-ilookup-tests (LUCache. small-map {} 2)))
- (testing "assoc and dissoc for LRUCache"
+ (testing "assoc and dissoc for LUCache"
(do-assoc (LUCache. {} {} 2))
- #_(do-dissoc (LUCache. {:a 1 :b 2} {} 2))))
+ (do-dissoc (LUCache. {:a 1 :b 2} {} 2))))
;; # LIRS

0 comments on commit ca4587b

Please sign in to comment.