internal static CachedResult GetCachedResult(int methodid, Binary key) { CachedResult result = new CachedResult() { Found = false }; object oResult = Cache.Get(CACHE_TYPE, GetCacheKey(methodid, key)); if (oResult == null) { using (LegionLinqDataContext legion = new LegionLinqDataContext(ConfigurationManager.ConnectionStrings["LegionConnectionString"].ToString())) { xspGetCachedResultResult cachedResult = legion.xspGetCachedResult(methodid, key).FirstOrDefault(); if (cachedResult != default(xspGetCachedResultResult)) { result.Result = cachedResult.Result; result.UpdatedOn = cachedResult.UpdatedOn; result.ExpiresOn = cachedResult.ExpiresOn; result.Found = true; CacheResultLocally(methodid, key, result); } } } else { result = (CachedResult)oResult; } return(result); }
internal static void CacheResultLocally(int methodid, Binary key, CachedResult cachedResult) { TimeSpan cachePadding = new TimeSpan(0, 0, Settings.GetInt("ResultCachingDurationPadding")); Cache.Add( CACHE_TYPE, GetCacheKey(methodid, key), cachedResult, (cachedResult.ExpiresOn + cachePadding), null ); }
internal static void ExpireResult(int methodid, Binary key, TimeSpan cachePadding) { CachedResult result = GetCachedResult(methodid, key); if (result.Found) { result.ExpiresOn = DateTime.Now; Cache.Add( CACHE_TYPE, GetCacheKey(methodid, key), result, (result.ExpiresOn + cachePadding), null ); } }
internal static void CacheResult(int methodid, Binary key, XElement parameters, XElement resultset) { DateTime?expiresOn = null; using (LegionLinqDataContext legion = new LegionLinqDataContext(ConfigurationManager.ConnectionStrings["LegionConnectionString"].ToString())) { legion.xspInsertCachedResult( methodid, parameters, resultset, key, ref expiresOn ); } CachedResult cachedResult = new CachedResult() { Result = resultset, UpdatedOn = DateTime.Now, ExpiresOn = (expiresOn == null ? DateTime.Now : (DateTime)expiresOn), Found = true }; CacheResultLocally(methodid, key, cachedResult); }