.NET 缓存 - 缓存很早就过期

.NET Caching - cache expires very early

我正在尝试使用 .Net 4.5 中的 MemoryCache 将对象存储 1 个月(绝对到期 - 从创建缓存起 1 个月)。

问题 - 缓存似乎会在一天内过期 - 实际上有时会在几个小时内过期。

代码段

// Setting the cache with absolute expiration time of 1 month:
string objName = "myObj";
MemoryCache memCache = MemoryCache.Default;
memCache.Add(tokenID, myObj, DateTimeOffset.UtcNow.AddMonths(1));

// Accessing the cache later
MemoryCache getCache = MemoryCache.Default;
getCache.Get(tokenID);

问题

  1. 我是否正确设置了缓存?我还没有看到任何使用 AddMonths() 的例子,但是有很多使用 AddDays() 的例子——不过这有关系吗?
  2. 我可以使用的绝对过期时间有上限吗? (我还没有遇到过任何设置缓存超过 30 天的例子,同时没有使用无限的过期时间。)
  3. 还有什么可能导致缓存过期这么快?

非常感谢!

检查您用于 Web 应用程序的 IIS AppPool 设置。在高级设置下,有一个空闲超时(分钟)的设置。如果您的站点空闲时间超过此时间段,工作进程将关闭。