Comments (2)
Hello, i understand the issue and see that it can be fixed. I'd like to know what your usecase is though. The 'average' usecase i have in mind is caching network requests which would have a TTL of seconds or maybe high milliseconds. This mean that the described issue is not really a thing.
If you can describe what you are doing (probably some caching internal to the application) then it helps me to take better decisions for all users in the future.
Also reasoning about fast expiration: on the one hand i can defend the current behaviour by saying that if it takes >expirationTime
to access the key that it would indeed be expired. On the other hand, if a key is retrieved and parked for further processing by GC/lock's later on i would consider it valid. Therefore the singleflight
option looks good.
Please go ahead with the PR.
from ttlcache.
Thanks, I'll float a PR by you in a day or two.
I was mistaken in the first post, my use case actually had:
- A TTL of 5 seconds
- Somewhere in the range of 100-1000 requests per second per key across 10ish keys.
- The loaderfunction takes 5ms to execute on average, but maybe sometimes much longer when there are network issues.
- We are caching some mutable database state in our application, and should/could use a queue or similar instead of a cache but this was easy to implement and good enough!
- We have many worker nodes, each that cache some frequently used state.
I'm not convinced the reproduction fully explains why sometimes I get the error (my TTL is much higher), but it is the only logic path I could see where it seems possible! Maybe there's some other lock contention I'm not considering.
from ttlcache.
Related Issues (20)
- How to get cache value without "Automatic expiration time extension"? HOT 1
- Add a method to check if a key exists HOT 1
- Way to get expired elements. HOT 2
- v3.0.1 doesn't have cache.GetOrSet method while it's documented in README.md of master branch HOT 5
- v3.0.1 doesn't have cache.Has method while it's documented in README.md of master branch HOT 2
- Question: about memory exceeding the limit HOT 1
- Is it thread safe? HOT 1
- Optimize getOpts allocation in Get() method using sync.Pool HOT 1
- Set without expanding the Expire time HOT 3
- `Range` panics when cache is empty HOT 1
- Feature request: Dedup same-key loader HOT 8
- Protect Range from empty cache HOT 1
- Add `GetContext()` method and `LoaderContext` interface HOT 1
- Lock-per-key functionality when using custom loader functions HOT 2
- Strange issue with OnEviction/OnInsertion hooks
- Proposal: Present cache items in order of oldest to newest
- SetUnsafe like IsExpiredUnsafe HOT 2
- Make the cache size configurable HOT 5
- Set doesn't reset TTL if the key already exists HOT 1
- Add OnUpdate method
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 ttlcache.