MemoryCache always returns “null” after first expiration

大兔子大兔子 提交于 2019-12-05 17:06:11
James McCormack

Resurrecting an old question, but I believe this problem is due to a bug that was only fixed in ASP.NET 4.5, but has a hotfix for earlier versions.

See this thread: MemoryCache Empty : Returns null after being set

Caching of this kind normally require your code to be in form "if an item is not in the cache then create the item, use the item that was created and also add to the cache, otherwise use the item from the cache". So normally it should be a problem if an item is not in the cache.

Common reason for items to disappear from the cache is high memory usage. In this case memory cache may immediately evict items as soon as they added to cache. This behavior is very common for applications running in 32 bit (x86), sepecially on servers handling a lot of requests or large amount of data.

To verify - collect memory conuters and process' bitness. Consider adding code to listen for removal of items from the cache by using MemoryCache.CreateCacheEntryChangeMonitor and corresponding events.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!