Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CCACHE-8: Added evict to LRUCache

  • Loading branch information...
commit 77174780ac030ca3e72d51cae4dfb3eb2ac286ee 1 parent beaa62d
@fogus fogus authored
View
8 src/main/clojure/clojure/core/cache.clj
@@ -172,6 +172,14 @@
(assoc lru item tick+)
tick+
limit))))
+ (evict [this key]
+ (let [v (get cache key ::miss)]
+ (if (= v ::miss)
+ this
+ (LRUCache. (dissoc cache key)
+ (dissoc lru key)
+ tick
+ limit))))
(seed [_ base]
(LRUCache. base
(into {} (for [x (range (- limit) 0)] [x x]))
View
6 src/test/clojure/clojure/core/cache/tests.clj
@@ -32,7 +32,9 @@
(defn do-dissoc [c]
(are [expect actual] (= expect actual)
2 (:b (dissoc c :a))
- nil (:a (dissoc c :a))))
+ nil (:a (dissoc c :a))
+ nil (:b (-> c (dissoc :a) (dissoc :b)))
+ 0 (count (-> c (dissoc :a) (dissoc :b)))))
(defn do-getting [c]
(are [actual expect] (= expect actual)
@@ -114,7 +116,7 @@
(do-ilookup-tests (LRUCache. small-map {} 0 2)))
(testing "assoc and dissoc for LRUCache"
(do-assoc (LRUCache. {} {} 0 2))
- #_(do-dissoc (LRUCache. {:a 1 :b 2} clojure.lang.PersistentQueue/EMPTY 0 2))))
+ (do-dissoc (LRUCache. {:a 1 :b 2} {} 0 2))))
(deftest test-ttl-cache-ilookup
(testing "that the TTLCache can lookup via keywords"
Please sign in to comment.
Something went wrong with that request. Please try again.