Permalink
Browse files

CCACHE-12: Handles empty LRU table case

  • Loading branch information...
1 parent 094363f commit beaa62d02c964b1c0114ab088c6a835ca4391f80 @fogus fogus committed Dec 9, 2011
Showing with 15 additions and 7 deletions.
  1. +11 −6 src/main/clojure/clojure/core/cache.clj
  2. +4 −1 src/test/clojure/clojure/core/cache/tests.clj
@@ -161,12 +161,17 @@
tick+
limit)))
(miss [_ item result]
- (let [tick+ (inc tick)
- k (apply min-key lru (keys lru))]
- (LRUCache. (-> cache (dissoc k) (assoc item result))
- (-> lru (dissoc k) (assoc item tick+))
- tick+
- limit)))
+ (let [tick+ (inc tick)]
+ (if-let [ks (keys lru)]
+ (let [k (apply min-key lru ks)]
+ (LRUCache. (-> cache (dissoc k) (assoc item result)) ;; expulsion case
+ (-> lru (dissoc k) (assoc item tick+))
+ tick+
+ limit))
+ (LRUCache. (assoc cache item result) ;; no change case
+ (assoc lru item tick+)
+ tick+
+ limit))))
(seed [_ base]
(LRUCache. base
(into {} (for [x (range (- limit) 0)] [x x]))
@@ -111,7 +111,10 @@
(deftest test-lru-cache-ilookup
(testing "that the LRUCache can lookup via keywords"
- (do-ilookup-tests (LRUCache. small-map {} 0 2))))
+ (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))))
(deftest test-ttl-cache-ilookup
(testing "that the TTLCache can lookup via keywords"

0 comments on commit beaa62d

Please sign in to comment.