Comments (2)
To accomplish this, two things would be required:
- A mechanism to enumerate all the items in the cache.
- Code that is able to analyze the size of an arbitrary type instance. This is relatively straightforward for classes/structs which do not contain references to other class instances. To contend with a graph of objects, the analyzer would need to be able to detect duplicates and avoid getting stuck in a loop analyzing cyclic references.
I can add an event solving part 1. This would enable you to have a background thread that periodically wakes up, enumerates all the items, then uses 2 to compute total size. I am philosophically opposed to a cache looking like a collection, but I understand this is useful for diagnostic purposes, and have already added a property to enable enumerating all the cached keys.
Writing code to solve part 2 would look something like this, but it won't scale well as reference count increases because resizing the hashset will be expensive. A slightly hackier way would be to serialize to binary, but that means all items must be serializable. Note that if your cached items reference a common global static (and these exist within framework types), such objects should be ignored since they do not contribute to item size and shouldn't be double counted. To handle things like this, you would need to reflect on the item type of each reference and filter by namespace.
I would like to keep this library focused on caching, and provide the hooks that make it useful/enable consumers. So, I can add the item enumeration, and that will enable you to roll your own memory estimate solution. You can use either of the above approaches to estimate item size if a relatively simple approach works in your use case. A generalized efficient, robust and configurable solution to 2 above is probably a dedicated NuGet package in itself.
from bitfaster.caching.
Sorry for the late reply. Yes, I think adding this feature will defeat the purpose of the library. Didn't really thought about it until you explained the reasons behind it. But having an event I think is an ok so that the consumers are aware of the penatlies of using it.
from bitfaster.caching.
Related Issues (20)
- FastConcurrentTLru's Constructor timetolive is not precise on liunx mac platform HOT 7
- Any plans to evict expired items on the background? HOT 2
- Expiration based on a Value's property? HOT 2
- NuGet package is missing intellisense xml file HOT 1
- Use NonBlocking instead of ConcurrentDictionary HOT 1
- [Feature request] individual items expiry HOT 1
- Current time provider HOT 6
- [Feature request] Allow to pass additional factory argument to the `GetOrAdd`/`GetOrAddAsync` cache methods HOT 2
- Entry left in cache configured with WithAtomicGetOrAdd when value factory throws HOT 4
- [Feature request] Atomic TryRemove HOT 3
- [Feature request] Expire after access LRU HOT 5
- [Feature request] Add TryRemove(K, out V) overload HOT 1
- [Feature request] Add MRU cache HOT 3
- [Bug] Cold queue increases infinitely for some partitions and cache sizes HOT 3
- [Feature Request] Add TryRemove(KeyValuePair<K, V>) overload HOT 2
- Clearing LFU cache doesn't actually clear it HOT 9
- Clearing ConcurrentLru leaves cache in broken state HOT 7
- `cache.Clear()` doesn't seem to be clearing entire cache HOT 6
- Is it possible to disable the eviction? HOT 2
- Doesn't look like capacity expiration/evicting is happening properly (might be specific to the initial population of the warm queue) HOT 3
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 bitfaster.caching.