AI OnAI Off
Is it a type-O that you are using sliding in one and nosliding in the other?
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 }
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
Installed .net 4.7.1 and it works again :)
There is cache issues with .net 4.7
Well, I did not do anything :)
Great that you solved it and thanks for explaining why here if anyone else got the same thing
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?