Search code examples
c#asp.netcachingmemoryhttpruntime.cache

How to find out how much memory is currently consumed by cache?


I'd like to modify the value of my Sliding Expiration time span based on how much memory is available. If the site's traffic is high at any point in time, more data will be added to the cache than during quieter periods. During those quiet periods I can increase the sliding expiration time span, thus allowing data to be stored longer. But when the site is busy I need to free up memory so I'm happier with a shorter time span.

So I guess my questions are as follows:

Is it possible for me to find out how much memory is being consumed by the items I've added to HttpRuntime.Cache? If so, how?

Does this sound like a realistic solution to the problem I've described?


Solution

  • It's unlikely you can come up with a good algorithm for 'helping' the Cache this way.

    Just make appropriate use of the priority parameter and let the Cache do its job.