Permalink
Browse files

Only update LRU usage map if cache contains the lookup key

  • Loading branch information...
1 parent 6a55835 commit a77b003d6593f7bde2f27f03ec52310b68aa0ea6 @frenchy64 frenchy64 committed Aug 5, 2014
Showing with 16 additions and 2 deletions.
  1. +3 −1 src/main/clojure/clojure/core/cache.clj
  2. +13 −1 src/test/clojure/clojure/core/cache/tests.clj
View
4 src/main/clojure/clojure/core/cache.clj
@@ -210,7 +210,9 @@
(hit [_ item]
(let [tick+ (inc tick)]
(LRUCache. cache
- (assoc lru item tick+)
+ (if (contains? cache item)
+ (assoc lru item tick+)
+ lru)
tick+
limit)))
(miss [_ item result]
View
14 src/test/clojure/clojure/core/cache/tests.clj
@@ -181,7 +181,19 @@
(assoc :a 1)
(assoc :b 2)
(assoc :b 3)
- .cache)))))
+ .cache))))
+
+ (is (= {:d 4 :e 5}
+ (-> (lru-cache-factory {} :threshold 2)
+ (hit :x)
+ (hit :y)
+ (hit :z)
+ (assoc :a 1)
+ (assoc :b 2)
+ (assoc :c 3)
+ (assoc :d 4)
+ (assoc :e 5)
+ .cache))))
(defn sleepy [e t] (Thread/sleep t) e)

0 comments on commit a77b003

Please sign in to comment.