public ListOnCache(string name, ICacheArea cache, CacheArea tempCacheArea = CacheArea.Temp, double tempCacheTime = 0) { TempCacheArea = tempCacheArea; TempCacheTime = tempCacheTime; Name = name; _dataSource = cache.DataSource; //LifeSpanInSeconds = lifeSpanInSeconds; }
/// <summary> /// Puts an item into the cache /// </summary> /// <typeparam name="tt">Type of object being stored</typeparam> /// <param name="area">What area to store object in</param> /// <param name="name">Name of object</param> /// <param name="obj">Object to store in cache location</param> /// <param name="lifeSpanSeconds"></param> public static void SetItem <tt>(ICacheArea area, string name, tt obj, double lifeSpanSeconds, string tags = "") { double?lSS = lifeSpanSeconds; if (lSS == 0) { lSS = null; } //name = area.Name + "_" + name; area.SetItem <tt>(name, obj, lSS, tags); //if (area.Area < CacheArea.Temp) //{ // SetItem(CacheArea.Temp, name + "_Request_TempCache", obj); //} }
/// <summary> /// Pull an item from the cache /// </summary> /// <typeparam name="tt">Type of object being requested</typeparam> /// <param name="area">What area object is stored in</param> /// <param name="name">Name of object</param> /// <param name="createMethod">Function passed in that will return a new object of type tt if cache location and name doesnt exist yet.</param> /// <param name="lifeSpanSeconds"></param> /// <returns></returns> public static tt GetItem <tt>(ICacheArea area, string name, Func <tt> createMethod, double lifeSpanSeconds, string tags = "") { try { double?lSS = lifeSpanSeconds; if (lSS == 0) { lSS = null; } if (!name.Contains("CacheEnabled") && !Instance.CacheEnabled) { if (createMethod != null) { return(createMethod()); } return(default(tt)); } if (area != null) { //name = area.Name + "_" + name; //if (area.Area < CacheArea.Temp) //{ // return GetItem(CacheArea.Temp, name + "_Request_TempCache", () => // { // return area.GetItem<tt>(name, createMethod, lSS); // }); //} //else { return(area.GetItem <tt>(name, createMethod, lSS, tags)); } } if (createMethod != null) { return(createMethod()); } } catch (Exception ex) { throw new Exception("Error:" + ex.Message + " retrieving cache item [" + name + "] on cache [" + area.ToString() + "]", ex); } return(default(tt)); }
public DictionaryCache(ICacheArea cacheTo, Func <string> getInstanceId, double lifeSpanInSeconds = 30 *60) { LifeSpanInSeconds = lifeSpanInSeconds; _cache = cacheTo; GetInstanceId = getInstanceId; }