我正在使用 .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 的目录存在。
谢谢你的帮助。