JuliaCollections / LRUCache.jl

An implementation of an LRU Cache in Julia
Other
56 stars 23 forks source link

Skip cache if value too big #37

Closed ericphanson closed 1 year ago

ericphanson commented 1 year ago
julia> lru = LRU{Int, Vector{Int}}(; maxsize=10, by=length)
LRU{Int64, Vector{Int64}}(; maxsize = 10)

julia> get!(lru, 1, 1:9)
1:9

julia> lru
LRU{Int64, Vector{Int64}} with 1 entry:
  1 => [1, 2, 3, 4, 5, 6, 7, 8, 9]

julia> get!(lru, 2, 1:11)
1:11

julia> lru
LRU{Int64, Vector{Int64}}(; maxsize = 10)

Since 1:11 is too big, I would prefer we just skip the cache here entirely, rather than evict any entries and end up with an empty cache.

Jutho commented 1 year ago

Yes I guess that would be an easy modification.