Comments (4)
Great, I'll try to have something done by next week!
About PR #160, I think it's very similar indeed! And I'd argue that in that case too maybe we should implement it as a wrapper. I'll see if it makes sense to use that idea and create two layers of wrappers: one with a generic cost, and another on top of that with the memory cost.
Answering @d-e-s-o :
May I ask what would happen if, as part of the mutation, the cache's limit is exceeded?
I think it should be the same behavior as if we had popped the value, and then inserted a larger one. Basically just evict older entries until we reach the desired threshold.
from lru-rs.
Not the author of the crate, just interested.
I thought about creating some sort of "Lock" object returned on the "get" function which would trigger a recalculation of the value's size when dropped, that way we can safely access and mutate values in the cache.
May I ask what would happen if, as part of the mutation, the cache's limit is exceeded?
from lru-rs.
Hey @felipou 👋
Anyway, I'm thinking about creating a pull request implementing these features, would that be a welcomed feature?
Definitely! This sounds like a broadly useful feature and, in fact, sounds similar to #160 which is about allowing the user to specify the "cost" of an element inserted into the cache.
One thing I'm still not sure about is: should we create a wrapper around LruCache, or try to implement this directly for LruCache (which I'm not even sure is possible without breaking compatibility with how it works right now)? I'm leaning toward creating a wrapper (like the crate I mentioned above).
I would also probably leans towards creating a wrapper at first since it would provide more flexibility from not having to worry about breaking compatibility.
from lru-rs.
Sorry for the drive-by shameless plug, just accidentally saw this issue so I thought I'd mention it, @felipou FYI the other day I needed an LRU crate which can do this, so I wrote my own which can.
One thing that's worth mentioning is that there are two sources of memory usage when inserting into a map:
- the inline size of the internal hash map,
- the memory on the heap used by the elements inserted into the hash map.
If you'd want to strictly and precisely limit memory usage you'd need to take both into the account. It's also worth remembering that the hash map grows in powers of two (so you can't just simply multiply inline item size by the number of items nor by the capacity to get its inline usage) and that also it has some control bytes which also take up extra space per entry.
(Although to be fair, considering that lru
boxes all of its elements if you're storing something big in the map then the inline size is probably going to be negligible.)
from lru-rs.
Related Issues (20)
- RwLock read() usage HOT 1
- Consider replacing HashMap with HashSet HOT 1
- Use after free bug in lru crate HOT 2
- Am I able to cache egui? HOT 1
- Lifetime fix is missing from the changelog for 0.7.4 HOT 2
- Full check leak report reachable bytes HOT 1
- Method that removes an entry corresponding to the key and returns both the key and the value
- Failed to build with feature "nightly" HOT 1
- Allow more liberal closure for `get_or_insert` HOT 2
- Could we have a new version with the updated `hashbrown` (and maybe others) dependency ? HOT 2
- Support const new
- Cache size 0 / Disable Cache HOT 3
- Cache key may not work HOT 5
- Debug not defined for custom BuildHasher
- Missing lifetime specifier in try_get_or_insert_mut? HOT 1
- Add `get_key_value` method
- Proposal to Integrate SIEVE Eviction Algorithm HOT 12
- Implement Clone on LruCache HOT 5
- Clone is only implemented for the default hasher HOT 1
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 lru-rs.