jellydator / ttlcache

An in-memory cache with item expiration and generics
MIT License
883 stars 115 forks source link

Mention DefaultTTL and NoTTL in Set() docs #96

Closed snirye closed 10 months ago

snirye commented 1 year ago

Set(key K, value V, opts ...[Option]) passing 0 as default is a bit confusing, and its also not documented

swithek commented 1 year ago

There's ttlcache.NoTTL for this. Though I agree, the Set() docs could probably mention it as one of the options.

snirye commented 1 year ago

Thanks for the quick response.

You probably meant DefaultTTL. But still, I think it not so natural to explicit mention this for using default behaviour, if it's possible to use same options mechanism that being used for the New function https://github.com/jellydator/ttlcache/blob/master/cache.go#L61 Like this: Set(key K, value V, opts ...SetOption)

I would be happy to implement if it help

swithek commented 1 year ago

You probably meant DefaultTTL.

I meant NoTTL, which is something you'd want to use if you don't want to set any TTL (that's what I gathered your intention was in the initial comment).

At the moment, there aren't any other SetOptions, so this change would be a bit premature. Besides, making a change like that would require us to release a new major version. And also, when this method was being designed, the goal was to have the TTL parameter as explicit as possible without having too much logic on top (e.g., having two methods: Set and SetWithTTL).

swithek commented 10 months ago

Fixed in https://github.com/jellydator/ttlcache/commit/542fed13c382c89a95f3b4dac5696acb1d850922