go-cache
go-cache copied to clipboard
Thoughts if you make a v2
Hi; thanks for a quick to use in-memory cache. If you make a v2, one thought on API design: if we already set the cache default timeout in the constructor, we should not have to remind it every time we set a cache item. I would think a better interface would be:
c.Set(key, val)
and allow it to be overridden with:
c.SetWithTimeout(key, val, duration)
// or
c.WithTimeout(duration).Set(key,val)
Another thought would be to add a max size parameter that could error if you attempt to set a value into cache after a given threshold is hit. This would provide some good back pressure for any system that becomes too aggressive.
Obviously, no change should happen in this version as to not break api backwards compatibility.
Thanks. I agree with everything.
FWIW: https://github.com/patrickmn/go-cache/commit/e7a9def80f35fe1b170b7b8b68871d59dea117e1
👍