Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only update LRU usage map if cache contains the lookup key

  • Loading branch information...
commit a77b003d6593f7bde2f27f03ec52310b68aa0ea6 1 parent 6a55835
Ambrose Bonnaire-Sergeant frenchy64 authored
4 src/main/clojure/clojure/core/cache.clj
View
@@ -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]
14 src/test/clojure/clojure/core/cache/tests.clj
View
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.