问题
I am using MemoryCache from System.Runtime.Caching of .NET 4 and I wish to invalidate the cache entry when a directory changes.
HostFileChangeMonitor is supposed to handle both files and directories so I am adding it like so:
var cacheItemPolicy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(30) };
cacheItemPolicy.ChangeMonitors.Add(new HostFileChangeMonitor(new List<string> { folder }));
but then I get an exception:
System.ArgumentOutOfRangeException: The UTC time represented when the offset is applied must be between year 0 and 10,000.
This only happens if I use the code in a ASP.NET website. It works fine from inside a console application.
I have found this on ms connect, but the directory I am adding to the HostFileChangeMonitor exists.
Thanks for your help.
回答1:
To answer my own question:
it seems that 4.0 has a bug when adding Directories to the HostFileChangeMonitor.
回答2:
Even when watching for a single file the error still exists. We are using HostFileChangeMonitor with a list of only one file and our client's Production server throws this exception. We recommended the MS fix: https://support.microsoft.com/en-us/kb/2346777 As soon as we can confirm the error is gone, i'll update the answer.
来源:https://stackoverflow.com/questions/11798498/using-memorycache-with-hostfilechangemonitor-init-to-a-directory-gets-argumentou