在HostFileChangeMonitor初始化到目录的情况下使用MemoryCache会得到ArgumentOutOfRangeException [英] Using MemoryCache with HostFileChangeMonitor init to a directory gets ArgumentOutOfRangeException

查看:78
本文介绍了在HostFileChangeMonitor初始化到目录的情况下使用MemoryCache会得到ArgumentOutOfRangeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using MemoryCache from System.Runtime.Caching of .NET 4 and I wish to invalidate the cache entry when a directory changes.

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

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 }));

但是我得到一个例外:

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

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

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.

感谢您的帮助.

推荐答案

要回答我自己的问题:
将目录添加到HostFileChangeMonitor时,似乎4.0存在一个错误.

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

这篇关于在HostFileChangeMonitor初始化到目录的情况下使用MemoryCache会得到ArgumentOutOfRangeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆