/// <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 Task <object> GetItemAsync(CacheArea area, string name, Type type, Func <Task <object> > createMethod, double lifeSpanSeconds, string tags = "") { var ca = Instance.GetCacheArea(area); try { double?lSS = lifeSpanSeconds; if (lSS == 0) { lSS = null; } if (!name.Contains("CacheEnabled") && !Instance.CacheEnabled) { return(createMethod?.Invoke()); } if (ca != null) { name = ca.Name + "_" + name; return(ca.GetItemAsync(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(null); //return await GetItemAsync(ca, name, createMethod, lifeSpanSeconds); }
public ListOnCache(string name, IDataSource cache, CacheArea tempCacheArea = CacheArea.Temp, double tempCacheTime = 0) { TempCacheArea = tempCacheArea; TempCacheTime = tempCacheTime; Name = name; _dataSource = cache; //LifeSpanInSeconds = lifeSpanInSeconds; }
public ListOnCache(string name, CacheArea cache, CacheArea tempCacheArea = CacheArea.Temp, double tempCacheTime = 0) { TempCacheArea = tempCacheArea; TempCacheTime = tempCacheTime; Name = name; _dataSource = Cache.Instance.GetCacheArea(cache).DataSource; //LifeSpanInSeconds = lifeSpanInSeconds; }
public IDictionary <string, object> GetDataDictionary(CacheArea area) { var nvl = GetCacheArea(area) as INameValueLister; if (nvl != null) { return(nvl.DataDictionaryGet()); } return(null); }
public async Task <IDictionary <string, object> > GetDataDictionaryAsync(CacheArea area) { var nvl = GetCacheArea(area) as INameValueLister; if (nvl != null) { return(await nvl.DataDictionaryGetAsync()); } return(null); }
public ICacheArea GetCacheArea(CacheArea area) { if (CacheAreas.ContainsKey(area)) { return CacheAreas[area]; } //area doesn't exist, go through each level till we find a level that works. var maxval = (from int v in Enum.GetValues(typeof (CacheArea)) select v).Max(); for (var a = (int)area; a<= maxval; a++) { var ea = (CacheArea) a; if (CacheAreas.ContainsKey(ea)) { return CacheAreas[ea]; } } return null; }
public ICacheArea GetCacheArea(CacheArea area) { if (CacheAreas.ContainsKey(area)) { return(CacheAreas[area]); } //area doesn't exist, go through each level till we find a level that works. var maxval = (from int v in Enum.GetValues(typeof(CacheArea)) select v).Max(); for (var a = (int)area; a <= maxval; a++) { var ea = (CacheArea)a; if (CacheAreas.ContainsKey(ea)) { return(CacheAreas[ea]); } } return(null); }
public void AddTaggedEntry(CacheArea cacheArea, string tags, string entryName) { if (string.IsNullOrWhiteSpace(tags)) { return; } var te = (from t in TaggedEntries.ToList() where t.CacheArea == cacheArea && t.EntryName.ToUpper() == entryName.ToUpper() select t).FirstOrDefault(); if (te == null) { te = new TaggedCacheEntry() { CacheArea = cacheArea, EntryName = entryName, Tags = "" }; TaggedEntries.Add(te); } if (string.IsNullOrWhiteSpace(tags)) { tags = ""; } if (string.IsNullOrWhiteSpace(te.Tags)) { te.Tags = ""; } var tarr = (tags.ToUpper() + "," + te.Tags.ToUpper()).Split(',').ToList(); tarr = (from t in tarr where !string.IsNullOrWhiteSpace(t) select t).Distinct().ToList(); tarr.Insert(0, ""); tarr.Add(""); te.Tags = String.Join(",", tarr); }
/// <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 async Task <tt> GetItemAsync <tt>(CacheArea area, string name, Func <Task <tt> > createMethod, string tags = "") { return(await GetItemAsync <tt>(area, name, createMethod, 0, tags)); }
public async Task<IDictionary<string, object>> GetDataDictionaryAsync(CacheArea area) { var nvl = GetCacheArea(area) as INameValueLister; if (nvl != null) { return await nvl.DataDictionaryGetAsync(); } return null; }
/// <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> public static void SetItem <tt>(CacheArea area, string name, tt obj, string tags = "") { SetItem(area, name, obj, 0, tags); }
/// <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> public static async Task SetItemAsync <tt>(CacheArea area, string name, tt obj, string tags = "") { await SetItemAsync(area, name, obj, 0, tags); }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <param name="lifeSpanSeconds"></param> /// <returns></returns> public static tt GetItem <tt>(CacheArea area, string name, tt defaultValue, double lifeSpanSeconds, string tags = "") { return(GetItem <tt>(area, name, () => defaultValue, lifeSpanSeconds, tags)); }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <returns></returns> public static tt GetItem <tt>(CacheArea area, string name, tt defaultValue, string tags = "") { return(GetItem <tt>(area, name, () => defaultValue, 0, tags)); }
public IDictionary<string, object> GetDataDictionary(CacheArea area) { var nvl = GetCacheArea(area) as INameValueLister; if (nvl != null) { return nvl.DataDictionaryGet(); } return null; }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <param name="lifeSpanSeconds"></param> /// <returns></returns> public static Task <object> GetItemAsync(CacheArea area, string name, Type type, object defaultValue, double lifeSpanSeconds, string tags = "") { return(GetItemAsync(area, name, type, async() => defaultValue, lifeSpanSeconds, tags)); }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <returns></returns> public static async Task <tt> GetItemAsync <tt>(CacheArea area, string name, tt defaultValue, string tags = "") { return(await GetItemAsync <tt>(area, name, async() => defaultValue, 0, tags)); }
public void ClearCache(CacheArea area) { GetCacheArea(area).ClearCache(); }
/// <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 async Task <object> GetItemAsync(CacheArea area, string name, Type type, Func <Task <object> > createMethod, string tags = "") { //await Task.Delay(10000); return(await GetItemAsync(area, name, type, createMethod, 0, tags)); }
/// <summary> /// Pull an item from the cache, cache instance will be initialized to whatever the default for the type tt is. /// </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> /// <returns></returns> public static Task <object> GetItemAsync(CacheArea area, string name, Type type, string tags = "") { return(GetItemAsync(area, name, type, async() => null, 0, tags)); }
/// <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 object GetItem(CacheArea area, string name, Type type, Func <object> createMethod, string tags = "") { return(GetItem(area, name, type, createMethod, 0, tags)); }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <param name="lifeSpanSeconds"></param> /// <returns></returns> public static async Task <tt> GetItemAsync <tt>(CacheArea area, string name, tt defaultValue, double lifeSpanSeconds, string tags = "") { return(await GetItemAsync <tt>(area, name, async() => defaultValue, lifeSpanSeconds, tags)); }
/// <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 async Task <tt> GetItemAsync <tt>(CacheArea area, string name, Func <Task <tt> > createMethod, double lifeSpanSeconds, string tags = "") { var ca = Instance.GetCacheArea(area); return(await GetItemAsync(ca, name, createMethod, lifeSpanSeconds, tags)); }
/// <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>(CacheArea area, string name, Func <tt> createMethod, string tags = "") { return(GetItem <tt>(area, name, createMethod, 0, tags)); }
/// <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 object GetItem(CacheArea area, string name, Type type, Func <object> createMethod, double lifeSpanSeconds, string tags = "") { var ca = Instance.GetCacheArea(area); return(GetItem(ca, name, createMethod, lifeSpanSeconds, tags)); }
/// <summary> /// Pull an item from the cache, cache instance will be initialized to whatever the default for the type tt is. /// </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> /// <returns></returns> public static object GetItem(CacheArea area, string name, Type type, string tags = "") { return(GetItem(area, name, type, () => null, 0, tags)); }
/// <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 async Task SetItemAsync(CacheArea area, string name, Type type, object obj, double lifeSpanSeconds, string tags = "") { var ca = Instance.GetCacheArea(area); await SetItemAsync(ca, name, obj, lifeSpanSeconds, tags); }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <returns></returns> public static object GetItem(CacheArea area, string name, Type type, object defaultValue, string tags = "") { return(GetItem(area, name, type, () => defaultValue, 0, tags)); }
/// <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(CacheArea area, string name, Type type, object obj, double lifeSpanSeconds, string tags = "") { var ca = Instance.GetCacheArea(area); SetItem(ca, name, obj, lifeSpanSeconds, tags); }
/// <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="defaultValue">Value to initialize the cache location to if cache location and name doesnt exist yet.</param> /// <param name="lifeSpanSeconds"></param> /// <returns></returns> public static object GetItem(CacheArea area, string name, Type type, object defaultValue, double lifeSpanSeconds, string tags = "") { return(GetItem(area, name, type, () => defaultValue, lifeSpanSeconds, tags)); }
/// <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 async Task <tt> GetItemAsync <tt>(CacheArea area, string name, Func <tt> createMethod, double lifeSpanSeconds, string tags = "") { return(await GetItemAsync <tt>(area, name, async() => createMethod(), lifeSpanSeconds, tags)); }
/// <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> public static async Task SetItemAsync(CacheArea area, string name, Type type, object obj, string tags = "") { await Task.Delay(10000); await SetItemAsync(area, name, type, obj, 0, tags); }
/// <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 Task <object> GetItemAsync(CacheArea area, string name, Type type, Func <object> createMethod, string tags = "") { return(GetItemAsync(area, name, type, async() => createMethod(), 0, tags)); }
/// <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> public static void SetItem(CacheArea area, string name, Type type, object obj, string tags = "") { SetItem(area, name, type, obj, 0, tags); }
public async Task ClearCacheAsync(CacheArea area) { await GetCacheArea(area).ClearCacheAsync(); }