expirable-cache
expirable-cache copied to clipboard
ContainsOrAdd function
The hashicorp lru.Cache implementation (https://github.com/hashicorp/golang-lru/blob/main/lru.go) contains a few other functions which are useful. I'm not sure why they don't include them in the simplelru or expirablelru implementations. In particular, the ContainsOrAdd function which checks for an item and either adds it or returns that it was found without updating recently used information. This is helpful in the case where multiple go routines are using the cache and may have duplicate data. Without such a function, a lock is required around the cache Get + Add operation.
Any plans to add something like this capability or a reason why it doesn't fit with the current implementation?
Feel free to add it if you need it, but I propose doing it for all versions from v1 to v3 for consistency.
Not sure if we still want this functionality but I've made a PR. I don't do this open source thing often so let me know if I've made any blunders.