Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CCACHE-12: Handles empty LRU table case

  • Loading branch information...
commit beaa62d02c964b1c0114ab088c6a835ca4391f80 1 parent 094363f
@fogus fogus authored
View
17 src/main/clojure/clojure/core/cache.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]))
View
5 src/test/clojure/clojure/core/cache/tests.clj
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.