Using MemoryCache with HostFileChangeMonitor init to a directory gets ArgumentOutOfRangeException

ぐ巨炮叔叔 提交于 2021-01-27 05:23:25

问题


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

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