Cache.Insert ("") with absolute expiration using UTC offset

I have several asp.net websites on a production server that suddenly have caching issues. The problem is that my cache values ​​are not saved when using the Cache.Insert method. Using Cache ["key"] = value still works.

For example, when I set a value like this, it is null when I retrieve it.

HttpRuntime.Cache.Insert("CacheTestVal", "Help Me!" null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);

When I set a value like this, I can get the expected value

Cache["CacheTestVal"] = "Help Me!";

I need to set an absolute expiration for the cache value, so I cannot use the Cache [""] method. All help is appreciated. Thank.

Edit: I found that setting absolute expiration as a UTC datetime works . I believe the problem is that the server does not convert absolute expiration to UTC when using DateTime.Now.

HttpRuntime.Cache.Insert("CacheTestVal", "Help Me!" null, DateTime.UtcNow.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);

The date / time and time zone are set as I would expect on the server, but maybe IIS does not recognize this, or is there a bad configuration value somewhere?

+4
source share
1 answer

This change in behavior may be caused by installing .NET 4.7 on the machine. The article below says that Microsoft will fix this in the next version of .NET and in the next patch.

Quoting parts of a Microsoft page:

Symptoms

, ​​Microsoft.NET Framework 4.7 . Cache, Cache.Insert(, , CacheDependency, DateTime, TimeSpan) , , DateTime ( ).

:

System.Web.Caching.Cache (UTC) . Cache.Insert(, , CacheDependecy, DateTime, TimeSpan) , UTC. , , Cache, , (GMT).

:

Cache.Add Cache.Insert.

:

​​ .NET Framework, .NET Framework 4.7.

:

https://support.microsoft.com/en-us/help/4035412/fix-expiration-time-issue-when-you-insert-items-by-using-the-cache-ins

http://vimvq1987.com/2017/08/episerver-caching-issue-net-4-7/

+3

Source: https://habr.com/ru/post/1680331/


All Articles