go-cache icon indicating copy to clipboard operation
go-cache copied to clipboard

Thoughts if you make a v2

Open sethgrid opened this issue 7 years ago • 3 comments

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.

sethgrid avatar Aug 23 '16 23:08 sethgrid

Thanks. I agree with everything.

patrickmn avatar Aug 24 '16 00:08 patrickmn

FWIW: https://github.com/patrickmn/go-cache/commit/e7a9def80f35fe1b170b7b8b68871d59dea117e1

patrickmn avatar Nov 25 '16 23:11 patrickmn

👍

sethgrid avatar Nov 26 '16 01:11 sethgrid