-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Limit Memory Size #179
Comments
I've seen generic guidance from those Microsoft Docs and StackOverflow that determining cache size is up to the developer creating the cache entries. There are historic GitHub issues on .net's repo by the maintainers saying they moved away from directly calculating memory size of cache entries due to inaccurance/complexity:
A cache entry's size is currently a unitless/arbitrary number supplied when adding entries to the cache. I can, for example, try to estimate determining the size of a cache entry by calculating the size of the string (char count * bytes [and null terminator]) and supply that with the 'size' in the cache entry options for FusionCache. An example of this size estimation can be found in Asp.Net's own implementation of One question I was about to open up an issue for, directly related to this, is how to provide a size value for the result returned by the factory method provided to |
I'm not quite sure if FusionCache does this, but for most in-memory cache's they are simply storing a reference to the object, they aren't wasting time doing any serialization, so there is no way to estimate object size. If you are serializing to some kind of string or byte array, then this could be accomplished easily, but you would never really want that for the in-memory cache. Best you could do is add a parameter and let the implementor send over the estimated size of an object. Maybe support a default extension method like .GetSizeForFusionCache() that the cache looks for and if the object implements it let it calculate itself. |
Hi @smthbh and thanks for using FusionCache! If you are talking about the size of the memory cache (either because you are not using the distributed cache or because you are interested only about that part), it is already possible: since FusionCache works on top of Normally, when creating a FusionCache instance, if you don't pass anything a new Hope this helps! |
Exactly!
Good question, and the answer is Adaptive Caching, which is fancy name for when you change some of the entry's options inside of the factory, while it is running. Let me know if this has helped you. |
Hi @jasenf
Yep, totally: serialization only happens when talking to the 2nd level (via the
Agree. |
That makes sense, thanks! |
Problem
There isn't a way to set a memory limit for the cache. Without this, it's possible that memory usage can grow without bound and crash the system.
Solution
Ideally, fusion cache would have an option to set the size of memory usage and prevent growing beyond this limit.
Additional context
Microsoft's docs on memory caching size limits are here: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-7.0#use-setsize-size-and-sizelimit-to-limit-cache-size
The text was updated successfully, but these errors were encountered: