Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MemoryCache with HostFileChangeMonitor init to a directory gets ArgumentOutOfRangeException

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.

like image 311
ador-mg Avatar asked Oct 07 '22 01:10

ador-mg


1 Answers

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

like image 65
ador-mg Avatar answered Oct 13 '22 11:10

ador-mg