示例#1
0
        /// <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);
        }
示例#2
0
 public ListOnCache(string name, IDataSource cache, CacheArea tempCacheArea = CacheArea.Temp, double tempCacheTime = 0)
 {
     TempCacheArea = tempCacheArea;
     TempCacheTime = tempCacheTime;
     Name          = name;
     _dataSource   = cache;
     //LifeSpanInSeconds = lifeSpanInSeconds;
 }
示例#3
0
 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;
 }
示例#4
0
        public IDictionary <string, object> GetDataDictionary(CacheArea area)
        {
            var nvl = GetCacheArea(area) as INameValueLister;

            if (nvl != null)
            {
                return(nvl.DataDictionaryGet());
            }
            return(null);
        }
示例#5
0
        public async Task <IDictionary <string, object> > GetDataDictionaryAsync(CacheArea area)
        {
            var nvl = GetCacheArea(area) as INameValueLister;

            if (nvl != null)
            {
                return(await nvl.DataDictionaryGetAsync());
            }
            return(null);
        }
示例#6
0
        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;
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
 /// <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));
 }
示例#10
0
 public async Task<IDictionary<string, object>> GetDataDictionaryAsync(CacheArea area)
 {
     var nvl = GetCacheArea(area) as INameValueLister;
     if (nvl != null)
     {
         return await nvl.DataDictionaryGetAsync();
     }
     return null;
 }
示例#11
0
 /// <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);
 }
示例#12
0
 /// <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);
 }
示例#13
0
 /// <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));
 }
示例#14
0
 /// <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));
 }
示例#15
0
 public IDictionary<string, object> GetDataDictionary(CacheArea area)
 {
     var nvl = GetCacheArea(area) as INameValueLister;
     if (nvl != null)
     {
         return  nvl.DataDictionaryGet();
     }
     return null;
 }
示例#16
0
 /// <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));
 }
示例#17
0
 /// <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));
 }
示例#18
0
 public void ClearCache(CacheArea area)
 {
     GetCacheArea(area).ClearCache();
 }
示例#19
0
        /// <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));
        }
示例#20
0
 /// <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));
 }
示例#21
0
 /// <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));
 }
示例#22
0
 /// <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));
 }
示例#23
0
        /// <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));
        }
示例#24
0
 /// <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));
 }
示例#25
0
        /// <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));
        }
示例#26
0
 /// <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));
 }
示例#27
0
        /// <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);
        }
示例#28
0
 /// <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));
 }
示例#29
0
        /// <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);
        }
示例#30
0
 /// <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));
 }
示例#31
0
 /// <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));
 }
示例#32
0
        /// <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);
        }
示例#33
0
 /// <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));
 }
示例#34
0
 /// <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);
 }
示例#35
0
 public async Task ClearCacheAsync(CacheArea area)
 {
     await GetCacheArea(area).ClearCacheAsync();
 }