-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WithKeepTTL #57
base: main
Are you sure you want to change the base?
WithKeepTTL #57
Conversation
@RelicOfTesla Hi 👋 |
@@ -82,6 +83,17 @@ func WithExpiration(exp time.Duration) ItemOption { | |||
} | |||
} | |||
|
|||
// WithKeepTTL is the expiration time to keep existing keys when calling Set. By default, it is replaced by the new time or never expires. | |||
func WithKeepTTL(_keep ...bool) ItemOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this better?
func WithKeepTTL(_keep ...bool) ItemOption { | |
func WithKeepTTL(keep bool) ItemOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are feasible, but I prefer to input less code because function names already have a certain intention
@@ -334,7 +353,7 @@ func (nc *NumberCache[K, V]) Increment(key K, n V) V { | |||
defer nc.nmu.Unlock() | |||
got, _ := nc.Cache.Get(key) | |||
nv := got + n | |||
nc.Cache.Set(key, nv) | |||
nc.Cache.Set(key, nv, WithKeepTTL()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not intend to make destructive changes to this library to ensure backward compatibility unless there is a good reason to do so. Why is this change necessary? Please provide a clear reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default rules for redis/memcached and more cache libraries... We do not recommend using different designs to avoid thinking burdens
Support KeepTTL option when update cache value.
Fix Increment/Decrement lose expiration time.