Overwriting entries in LRU-cache deletes LRU key-values unnecessarily

Description

To "overwrite" the value in an LRUCache, one uses assoc. Surprisingly, another k,v entry is evicted, even though the total number of items in the cache should not be increased by overwriting.

Demo:

(def C0 (lru-cache-factory {} :threshold 3))
; --> #<Var@7ec74910: {}>

(def C1 (-> C0 (assoc :a 1) (assoc :b 2) (assoc :c 3)))
; --> #<Var@315863e4: {:c 3, :b 2, :a 1}>

(-> C1 (assoc :a 4) (assoc :a 5) (assoc :a 6))
; --> {:a 6}

Environment

None

Activity

Show:
Sean Corfield
March 1, 2018, 4:50 AM

Closing out all resolved issues as of 0.6.5 in order to track the next release.

import
August 23, 2012, 1:28 AM

Works for me in 0.6.2. Thanks, Fogus!

(-> (cache/lru-cache-factory {} :threshold 2)
(assoc :a 1)
(assoc :b 2)
(assoc :b 3))

; {:b 3, :a 1}

import
July 16, 2012, 7:30 PM

It appears v0.6.1 still has not fixed the issue

(-> (cache/lru-cache-factory {} :threshold 2)
(assoc :a 1)
(assoc :b 2)
(assoc :b 3))
{:b 3}

Fogus
July 13, 2012, 4:46 PM

v0.6.1 pushed to Maven Central.

Fogus
July 12, 2012, 9:24 PM

version 0.6.1 has been pushed out to Maven central.

Completed

Assignee

Fogus

Reporter

import

Labels

None

Approval

None

Patch

None

Priority

Major