I have a high traffic site that needs to see results of a game every 10 minutes. These games are stored in cache and filtered through there for various means. There could be 200+ events going on during the weekend.
I noticed some high GC going on which causes a site delay. After some investigation I noticed my Gen2 is three times larger than Gen0 and nothing in Gen1.
This led me to believe that my cached objects eventually go to Gen2, and stay there even when expired. Then high garbage collection occurs on those Gen2 objects. Is there a better approach than what I am doing in the code below and could this be the issue with my high GC?
public static T GetInitializedCache<T>(string key, Func<CacheData<T>> getData, int minutes, bool skip = false)
{
if (!skip)
{
key = key.ToLower();
var value = HttpRuntime.Cache[key];
if (value == null || value.GetType() != typeof(T))
{
CacheData<T> data = getData();
if (data != null && data.Data != null && Config.Debugging.EnableCaching)
{
HttpRuntime.Cache.Insert(key, data.Data, null, DateTime.Now.AddMinutes(data.Minutes ?? minutes), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
}
return data != null ? data.Data : default(T);
}
return (T)value;
}
else
{
var data = getData();
return data != null ? data.Data : default(T);
}
}

