I have ASP.Net application with a simple cache helper. Under VS web server it works fine. Under IIS 6.0 cache doesn't work- object, was saved previos, doesn't returns after a minute (with no exception). What could be wrong?
public static class CacheHelper
{
public static string Share<T>(T @object, TimeSpan period)
{
var uniqueKey = Guid.NewGuid().ToString();
HttpContext.Current.Cache.Add(uniqueKey, @object, null, Cache.NoAbsoluteExpiration,
period, CacheItemPriority.BelowNormal, null);
return uniqueKey;
}
public static void ShareViaCookie<T>(string key, T @object, TimeSpan period)
{
var cachedObject = GetFromCookie<T>(key);
if (ReferenceEquals(cachedObject, null))
{
var uniqueKey = Share(@object, period);
HttpContext.Current.Response.Cookies.Set(new HttpCookie(key, uniqueKey)
{
Expires = DateTime.Now.AddYears(1)
});
}
else
{
HttpContext.Current.Cache[GetKeyFromCookie(key)] = @object;
}
}
public static T GetShared<T>(string key)
{
string uniqueKey = HttpContext.Current.Request.QueryString[key];
return !string.IsNullOrEmpty(uniqueKey) ? (T)HttpContext.Current.Cache.Get(uniqueKey) : GetFromCookie<T>(key);
}
private static T GetFromCookie<T>(string key)
{
string uniqueKey = GetKeyFromCookie(key);
return !string.IsNullOrEmpty(uniqueKey) ? (T)HttpContext.Current.Cache.Get(uniqueKey) : default(T);
}
private static string GetKeyFromCookie(string key)
{
return HttpContext.Current.Request.Cookies[key]
.IIf(it => it != null, it => it.Value, it => null);
}
}