hashicorp / golang-lru

Golang LRU cache
Mozilla Public License 2.0
4.32k stars 498 forks source link

New2Q with size = 1 fails to create the cache #51

Open mkeeler opened 6 years ago

mkeeler commented 6 years ago

This seems to be due to calculating the frequent and recent LRU sizes and being truncated to 0. So when those get created the following error is returned:

"Must provide a positive size"

Obviously this is really edge casey as who would want a cache of size 1 (except I did when implementing some unit tests for Consul).

rsjethani commented 5 years ago

@mkeeler you are right this is an edge case. However the code is not wrong when it denies creation of a size 1 2Q cache. A size 1 2Q cache makes no sense.

But yes the code should give proper error message instead of the current confusing one. So here is a small change I have made via PR #60