All PRs and issues from go-cache (excluding some fluff) and why they have or haven't been included.
This was included, although perhaps not exactly as mentioned, but the use case or issue that was reported should be resolved.
-
add Expire ExpireAt command by zebozhuang
Update item with same expiry by pranjal5215
Add UpdateExpiration method. by dossy
add GetWithExpirationUpdate by sbabiv
GetWithExpirationUpdate - atomic implementation by paddlesteamer
best way to extend time on an not expired object?
Adding some utility functions to cache: by EVODelavegaAdded as
Touch()
; PR 55 also addedPop()
, which seems like a useful thing to add as well. -
Add GetPossiblyExpired() by Freeaqingme
Add method to retrieve CacheItem rather than the value of the item by rahulraheja
Add functionality allowing to get expired value (stale) from cache by oskarwojciski
Get Expired ItemGet expired cache items; added as
GetStale()
.I didn't use
GetItem()
orGetCacheItem()
as I felt that it should be clear from the name you're getting potentially expired items.Potentually, a
GetStaleWithExpiration()
could be added too; but I'm not sure how valuable that is. -
Add Iterate by youjianglong
Add method for getting all cache keys by alex-ant
Add method for delete by regex rule by vmpartnerAll of them are essentially the same issue: do something with all keys. Added a
Keys()
method to return an (unsorted) list of keys. -
Add Map function (Read/Replace) in single lock
added atomic list-append operation by sgeisbacherBoth of these issues are essentially the same: the ability to atomically modify existing values. Instead of adding a []string-specific implementation a generic Modify() seems better to me, so add that.
-
Add remove method, if key exists, delete and return elements by yinbaoqiang
Added as Pop()
Issues and PRs that were not included with a short explanation why. You can open an issue if you feel I made a mistake and we can look at it again :-)
-
Add OnMissing callback by adregner
Add Memoize by clitetailor
GetOrSet method to handle case for atomic get and set if not exists by techniciantedThese all address the same problem: populate data on a cache Get() miss.
The problem with a
GetOrSet(set func())
-type method is that the map will be locked while theset
callback is running. This could be fixed by unlocking the map, but then it's no longer atomic and you need to be very careful to not spawn severalGetOrSet()
s (basically, it doesn't necessarily make things more convenient). Since a cache is useful for getting expensive-to-get data this seems like it could be a realistic problem.This is also the problem with an
OnMiss()
callback: you run the risk of spawning a bucketload of OnMiss() callbacks. I also don't especially care much for the UX of such a callback, since it's kind of a "action at a distance" thing.This could be solved with [
zsync.Once
](zstd/once.go at master) though, then only subsequent GetOrSet calls will block. The downside is that is that keys may still be modified with Set() and other functions while this is running. I'm not sure if that's a big enough of an issue.I'm not entirely sure what the value of a simple
GetOrSet(k string, valueIfNotSet interface{})
is. If you already have the value, then why do you need this? You can just set it (or indeed, if you already have the value then why do you need a cache at all?)For now, I decided to not add it.
-
what if onEvicted func very slow
You can start your own goroutine if you want; this can be potential tricky/dangerous as you really don't want to spawn thousands of goroutines at the same time, and it may be surprising for some.
-
Feature request: add multiple get method.
The performance difference is not that large compared to a for loop (about 970ns/op vs 1450 ns/op for 50 items, and it adds an alloc), it's not clear how to make a consistent API for this (how do you return found? what if there are duplicate keys?), and overall I don't really think it's worth it.
-
Feature request: max size and/or max objects
An Unobtrusive LRU for the best time cache I've used for go by cognusionSee FAQ; maybe we can add this as a wrapper and new
zcache.LRUCache
or some such. Max size is even harder, since getting the size of an object is non-trivial. -
Added BST for efficient deletion by beppeben
Seems to solve a specific use case, but makes stuff quite a bit more complex and the performance regresses for some use cases.
-
expose a flag to indicate if it was expired or removed in OnEvicted()
add isExpired bool to OnEvicted callback signature by AshtonianUnclear use case; although passing the Item instead of value to OnEvicted() wouldn't be a bad idea (but incompatible).
-
Add function which increase int64 or set in cache if not exists yet by oskarwojciski
This makes the entire increment/decrement stuff even worse; need to rethink that entire API. An option to set it if it doesn't exist would be better.
-
Changing RWMutexMap to sync.Map by vidmed
Unclear if this is a good idea, because performance may either increase or regress. Won't include.
-
Delete from the cache on Get if the item expired (to trigger onEvicted) by fdurand
Not a good idea IMO, makes Get() performance unpredictable, and can be solved by just running the janitor more often. Would also complicate the "get even if expired" functionality.
-
Add a Noop cache implementation by sylr
Request: Add formal interface for go-cacheYou don't really need this; you can define your own interfaces already. Mocking out a in-memory cache with a "fake" implementation also seems like a weird thing to do. Worst part is: this will lock down the API. Can't add new functions without breaking it. Not adding it.
-
Add prometheus metrics by sylr
This PR makes things worse for everyone who doesn't use Prometheus (i.e. most people). Clearly this is not a good idea. You can still add it as a wrapper if you want.
-
Flush calls onEvicted by pavelbazika
This is a breaking change, since Flush() now works different. You can also already do this by getting all the items and deleting one-by-one (or getting all the items, Flush(), and calling onEvict()).
-
The OnEvicted function is not called if a value is re-set after expiration but before deletion
I'm not so sure this is actually a bug, as you're overwriting values.
-
Allow querying of expiration, cleanup durations
You can already get a list of items with Items(); so not sure what the use case is here? Not clear enough to do anything with as it stands.
-
Implemented a faster version of the Size() function
Because this only counts primitives (and not maps, structs, slices) it's very limited. This kind of stuff is out-of-scope for v1 anyway.