Comments (5)
Thanks, hadn't spotted that.
Would have to think about it, I understand the @mgaffney's point. Adding a context would allow some control over the goroutine without it being an official method of the cache, but does feel like another workaround. Maybe there is a need for a workaround though, leaking goroutines isn't ideal.
At least with a context or the Close() we have some control over the issue. An issue from closing without properly handling the other functions calling the cache is a user error in implementation of the cache that can be rectified, or shouldn't occur in the first place if implemented per the documentation. Whereas a leaking goroutine is a code error in the library rather than a user error and one that can't be fixed by the user or worked around.
from golang-lru.
Please see #116 (comment) for the reasons I removed it, it was a requirement for merging as I understood it.
from golang-lru.
It would be great to have this, as running code with the -race detector currently fails due to this issue. I think it would be better to add a .Close() method to let the user call that when they are done (opposed to runtime.SetFinalizer as in the linked PR).
from golang-lru.
I'd like to add this for expirable-lru, but I don't know why the code is commented out here, and there's no mention of the reason in the commit message https://github.com/hashicorp/golang-lru/blob/main/expirable/expirable_lru.go#L277
from golang-lru.
I have come here with the same issue. It seems it was implemented in #116 by @paskal, but can't understand why the close option was removed.
expirable.NewLRU should probably receive a context so we can have control over that goroutine that is started as a replacement to .Close if it is going to be removed.
This has come up because all my tests automatically check for leaking goroutines by ensuring the number of goroutines at the beginning of the test is the same as it is at the end, and without being able to call a cancel() on a context passed to the LRU goroutine the tests will keep failing.
from golang-lru.
Related Issues (20)
- Why does TwoQueueCache have no onEvicted callback? HOT 1
- Please don't break public API without major bump HOT 1
- onEvicted is called with incorrect item when a previous Add overwrites an existing item HOT 11
- v2.0.3 introduced breaking changes and is breaking our build HOT 9
- how to update the cache element ? HOT 1
- Is there a plan to add an interface to get the capacity of the lru-cache
- Did you empty 1.01v HOT 1
- Expirable LRU can return nil value with ok = true HOT 3
- Example output is not matched with actual output HOT 4
- AddMany?
- Delayed deletion of entries in expirable cache HOT 1
- Proposal to Integrate SIEVE Eviction Algorithm HOT 11
- we have encounter an strange panic, we still working on it. HOT 1
- How to update a key expiration in the cache? HOT 3
- Request for `RemoveWithoutEvict` API.
- The return of the example is inconsistent with the actual return
- Suggestion for GetWithExpiration method for expirable cache
- Addition of AddWithTtl to Expirable cache HOT 1
- index out of range panic while calling "Keys()" function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from golang-lru.