I was looking at using the LruCache as a queue for items that needed to be cleaned up but might be revived, and thought LruCache::insert was returning the removed least recently used item rather than the old value. The insert method does match how normal hashmaps work, so it shouldn't be changed and is correct as-is. But the documentation makes it sound like it's going to return the value at the front of the LRU list without mentioning the old value for the given key.
It would also be nice if there was an insert_lru or similar method that does return the least recently used item if relevant. Possibly as an enum { OldValue(V), LRUValue(K, V), Nothing}, since it's impossible to have both an old value and remove the least-recent item in the same insert call.
I was looking at using the LruCache as a queue for items that needed to be cleaned up but might be revived, and thought
LruCache::insert
was returning the removed least recently used item rather than the old value. The insert method does match how normal hashmaps work, so it shouldn't be changed and is correct as-is. But the documentation makes it sound like it's going to returnthe value at the front of the LRU list
without mentioning the old value for the given key.It would also be nice if there was an
insert_lru
or similar method that does return the least recently used item if relevant. Possibly as anenum { OldValue(V), LRUValue(K, V), Nothing}
, since it's impossible to have both an old value and remove the least-recent item in the same insert call.