HttpRuntime.Cache is never null on my dev computer

Vote:
 

Hi

This is prob not epi releated. But since you all are working with epi maybe some of you have the same issue.

The code is working fine in prod and test.

But on my local computer (Windows 10 latest update, web.config has httpRuntime targetFramework="4.6.2") the cache never expires

If i do this line of code (execute one time)

HttpRuntime.Cache.Insert("test", "test", null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration);

This will never be null.

HttpRuntime.Cache["test"];

I expect it to be null after 1 min.

But this one works fine

private static ISynchronizedObjectInstanceCache SyncedCache
= ServiceLocator.Current.GetInstance();

Execute ones

var policy= new CacheEvictionPolicy(TimeSpan.FromMinutes(1), CacheTimeoutType.Sliding);
SyncedCache.Insert("test", "test", policy);

This will be null after 1 min

var thisOneWorks = SyncedCache.Get(cacheKey);

Anyone?

#185469
Edited, Nov 21, 2017 10:34
Vote:
 

Is it a type-O that you are using sliding in one and nosliding in the other?

#185474
Nov 21, 2017 11:14
Vote:
 

Here is my Cachehelper. 

public static T Get<T>(string cacheKey, Func<T> getDataMethod, int minutesToCache = 5, bool forceUpdate = false)
{
if (!forceUpdate && HttpRuntime.Cache[cacheKey] != null)
{
// -> Found in cache AND we are not forcing update
return (T)HttpRuntime.Cache.Get(cacheKey);
}
T data = getDataMethod();

if (data != null)
{
HttpRuntime.Cache.Insert(cacheKey, data, null, DateTime.Now.AddMinutes(minutesToCache), Cache.NoSlidingExpiration);
}
return data;
}

Example:

public static List<string> GetCurrencyList()
{
return CacheHelper.Get("CurrencyHelper.GetCurrencyList", () => GetCurrencyListNoCache(), 60);
}

private static List<string> GetCurrencyListNoCache()
{
// If i add a log line here it will hit once And never again. If i recycle it will hit
}



#185475
Edited, Nov 21, 2017 11:27
Vote:
 

Maybe this is the problem?

https://stackoverflow.com/questions/44805744/cache-insert-with-absolute-expiration-off-by-utc-offset

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

I have .net 4.7 on my dev computer

#185479
Nov 21, 2017 11:58
Vote:
 

Installed .net 4.7.1 and it works again :)

There is cache issues with .net 4.7

#185480
Nov 21, 2017 12:11
Vote:
 
<p>Thanks for your reply Henrik</p>
#185481
Nov 21, 2017 12:12
Vote:
 

Well, I did not do anything :)

Great that you solved it and thanks for explaining why here if anyone else got the same thing

#185483
Nov 21, 2017 12:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.