2

I have a legacy application, rather large that implements both System.Web.Caching and System.Runtime.Caching. Yes that's right, there are services running in the same application pool that could be using either.

My question is how will these interact as far as memory limits are concerned ? From what I have read the default limit for MemoryCache is 60% of available memory which is great. I suppose the question more directly is then does the System.Web.Caching instance share that same 60% ?

I also have a named instance of MemoryCache limited to 100mb.

What I want to understand is what happens to my MemoryCache instance if or when System.Web.Caching gets filled and ejections are forced ?

DuctTaper
  • 29
  • 1

1 Answers1

1

When cache reaches its limits it start to evict its oldest items or items with closest expiration times, depends on policy. You can set amount of memory for your Web Cache. Check this post, it explains all of this . All caches work in a similar way. Also, look into NCache. They have free version. It allows to do so much more with cache especially for Web Farms.

so, you asked: how will these interact as far as memory limits are concerned? - They will not interact. They will do what they do for each one separately. Each will have limited resources. Try to use one cache, instead of multiple, you will save resources for actually caching items.

Community
  • 1
  • 1
T.S.
  • 18,195
  • 11
  • 58
  • 78
  • "they will not interact" seems odd or at a minimum problematic. Both types claim they default to 60% of available memory. That means with both in play you could end up with a LOT of disk I/O since 120% of available memory is now possible. I do not have a choice at this time to commit to just one. This is a large, legacy application so I must account for both. – DuctTaper Nov 03 '16 at 10:22
  • @DuctTaper Lets define "interact". - *to act on or in close relation with each other*. This is not happening. These are 2 separate objects-they don't know of each other. They work independently. They affect each other incidentally. Their memory usage will be limited by OS, .net, IIS and cache config. There will be no 120%. From OS to your .net app, your cache will be squeezed to lesser limits and if you add more RAM these limits may grow. So, your 2 caches will share whatever memory available in your .net running app. If they both start to grow, they both will start evicting items. – T.S. Nov 03 '16 at 13:24
  • @DuctTaper Imagine squeezing 2 balloons into small box. You will have to start deflating both of them until they are flat enough to fit in. But at this point they are ineffective because they don't do their job and they hold little air and can't fly. Same with cache - small memory = less items and more evictions. And then take 32bit applications - the situation even worse. In 64bit you can get a bigger box but in 32bit you are limited to a small box. I even think there is something like 1.5G hardstop limit – T.S. Nov 03 '16 at 13:28