5

我正在使用 .NET 4 的 System.Runtime.Caching 中的 MemoryCache,并且我希望在目录更改时使缓存条目无效。

HostFileChangeMonitor 应该同时处理文件和目录,所以我像这样添加它:

var cacheItemPolicy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(30) };
cacheItemPolicy.ChangeMonitors.Add(new HostFileChangeMonitor(new List<string> { folder }));

但后来我得到一个例外:

System.ArgumentOutOfRangeException: The UTC time represented when the offset is applied must be between year 0 and 10,000.

仅当我在 ASP.NET 网站中使用代码时才会发生这种情况。它可以在控制台应用程序内部正常工作。

我在 ms connect 上找到了这个,但是我添加到 HostFileChangeMonitor 的目录存在。

谢谢你的帮助。

4

2 回答 2

4

To answer my own question:
it seems that 4.0 has a bug when adding Directories to the HostFileChangeMonitor.

于 2012-10-22T12:46:47.843 回答
0

即使在查看单个文件时,错误仍然存​​在。我们将 HostFileChangeMonitor 与仅包含一个文件的列表一起使用,并且我们客户端的生产服务器抛出此异常。我们推荐 MS 修复: https: //support.microsoft.com/en-us/kb/2346777 一旦我们确认错误消失,我会更新答案。

于 2016-07-04T08:19:54.700 回答