Conversation
|
I'd love to have this merged soon! 🙌 |
|
This package hasn't seen any updates for a number of years, so it seems unmaintained. I'll probably add this, or a version of this, to the fork I use. This is an incompatible change though, so it needs to be as a v2. |
|
Keep me posted once version 2 is out, then I'll probably switch to zcache. |
|
@arp242 If there's anything I can do to help, let me know. |
|
Working on adding this, as I figured it would be a good project to get up to speed with generics. I wonder if there's a more convenient way to do this? It's just a bit of needless indirection; I'd rather do something like For the time being I added: So you can do |
|
You could create function like this instead of method |
|
I put a v2 branch over here, with some other incompatible changes I made last year too: https://github.com/arp242/zcache/tree/v2 I'm not entirely convinced about using a |
|
I think I'll leave out It's a bit more typing, bit I think that's okay. Any feedback @muety or @sschiz? I migrated my own application to v2 and it all seems to work grand, but a second pair of eyes never hurts. |
|
@arp242 what is the difference between these:
In fact, it's the same thing, and Modify method is boilerplate. |
|
The advantage of But what really should happen is: Because Modify() locks from "get value" to "set value" you'll get the correct behaviour: the second goroutine will block until the first one is done, and will use the correct value. This is/was also the advantage of having Increment. |
|
Initially go-cache is not thread-safe like built-in map. It's not a problem. Anyway there's sync.Mutex. |
|
I'm not sure if I follow? All operations should be thread-safe (in go-cache, and zcache); this is why the |
|
I'm sorry. It was misunderstanding. |
|
Haha, okay; no worries! I updated the documentation a bit as a result because I realized it wasn't all that clear, so it was useful regardless :-) |
|
Here you go: https://github.com/willboland/simcache |
I have rewritten go-cache to generic one.
Originally
Cachehas incrementing and decrementing methods, but any constraint doesn't allow types to be added and subtracted. I decided to implement the original cache usinganyrestriction, while removing these methods, and also to implement extendedCachenamedOrderedCachethat has incrementing method.I didn't really touch the sharded cache. I made the cached value
comparable. The key wasn't touched. Internally the sharded cache has OrderedCache.Last but not least, I initiated the
go.modfile because a dependency ofgolang.org/x/expwas required.