none
MemoryCache doesn't honor expiration RRS feed

  • Question

  • We have a web application in which we are using MemoryCache.  What we see is that sometimes during load testing MemoryCache doesn't honor the AbsoluteExpiration time.  In some of our testing, it seems to work fine and others it doesn't work at all, like the cache isn't even there.  We are using the defaults for cache settings.  Our web app doesn't use a lot of memory compared to the total system memory (about 500MB usage with 16GB system memory). 

    Is there anything special we should be doing to configure MemoryCache?  Should we be setting CacheMemoryLimit or PhysicalMemoryLimit?  If so, should we do this in the config file or programmatically?  Any other ideas?

    System: A VM running Windows Server 2008 R2 SP1, Xeon CPU E5-2670, 16GB RAM

    Application: Web app using MVC, Web Forms, .NET 4.5, running in IIS 7.

    Wednesday, December 2, 2015 3:08 PM

Answers

  • Hi bdavisson,

    >>Is there anything special we should be doing to configure MemoryCache?  Should we be setting CacheMemoryLimit or PhysicalMemoryLimit?  If so, should we do this in the config file or programmatically?  Any other ideas?

    I would suggest you to set your CacheMemoryLimitMegabytes Property of  <memoryCache> Element to 2G. Please refer to https://msdn.microsoft.com/en-us/library/dd941872(v=vs.110).aspx for more details. At the same time, please monitor your memory usage. If MemoryCache still doesn't honor the AbsoluteExpiration time, this is not a CacheMemoryLimit issue.   I  searched more, here I found a thread MemoryCache AbsoluteExpiration acting strange, Please have a look.

    Op resolved this issue by overwriting the value using reflection and clearing the default MemoryCache instance to reset everything.

    By the way, since you are developing Web app using MVC, Web Forms, please also repost this issue in MVC forum for more professional response.  

    Hope this helps.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 3, 2015 6:02 AM