CacheManager
CacheManager copied to clipboard
Priority in SystemWebCacheHandle
Is there a simple way to specify priority for memory cache? Tried to inherit from SystemWebCacheHandle, but it seems I need to reimplement it's code almost entirely.
Hi @Cherepoc , What priority do you mean exactly, the per cache item policy setting? And why do you want to set it manually? Thanks!
Thanks for reply! Not necessary per item, but per cache configuration would be nice. As I know, .net memory cache removes items if they take too much space. In my project some cached items are requested much more frequently then others, so I would like to lower their chance of removal. I read setting caching priority is one way to do that, but I can't find the way to do that in you library. A way to set that on configuration level would be nice. Or maybe there are better options to accomplish my task? Thanks!
Ok got it,
For System.Web.Caching in CacheManager, all items gets priority Normal
. Setting the priority to all items to something else wouldn't mean anything I guess because the logic during memory pressure checks would just look at the lowest priority items first. If they all have the same priority, it'll probably remove the least used first (not sure).
So, setting the priority for the CacheManager instance would not help a lot right? Setting the priority so that items never get removed would also be a bad idea because you could run oom.
But, there are at least some settings you can put into web.config
For System.Web.Caching: https://msdn.microsoft.com/en-us/library/ms228248(v=vs.85).aspx For System.Runtime.Caching: https://msdn.microsoft.com/en-us/library/dd941875(v=vs.110).aspx (in that case, CacheManager picks up the profile by naming the cache handle instance = profile name).
Hope that helps
Why won't setting priority for CacheManager help? I planned to use different cache managers for objects with different priority. But anyway, it seems that profiles will do the trick, thanks!
You are right, different instances would work in System.Web.Caching because they actually share the same cache instance. Let me know how it goes ;)
Hm, I can't find any priority options in those profiles.
Yup, no you cannot set the priority there. Anyways, I'll mark this as enhancement / feature request. It might be a bigger change because it's not that easy to hook up custom settings for a cache handle all the way through the configuration system. I might have to add some more generic thing... we'll see. For now, you'd have to live without that feature ;)
Ok, thanks! Looking forward for it.