コード例 #1
0
        /// <summary>
        /// Formats the concatenation of the cache tag
        /// </summary>
        /// <param name="type"></param>
        /// <param name="identifier"></param>
        /// <returns></returns>
        public static string FormatTag(CacheTags type, dynamic identifier)
        {
            if (identifier == null)
            {
                identifier = "null";
            }
            string id = type.ToString() + identifier.ToString();

            return(id);
        }
コード例 #2
0
ファイル: DBConnectorProxy.cs プロジェクト: QuantumArt/QA.DPC
 public string GetUrlForFileAttribute(int fieldId)
 {
     return(_cacheProvider.GetOrAdd($"DBConnectorProxy.GetUrlForFileAttribute_{fieldId}",
                                    CacheTags.Merge(CacheTags.QP8.Site, CacheTags.QP8.Field),
                                    TimeSpan.FromMinutes(10),
                                    () =>
     {
         return GetConnector().GetUrlForFileAttribute(fieldId);
     }));
 }
コード例 #3
0
 /// <summary>Expire all cached keys linked to specified tags.</summary>
 /// <param name="tags">
 ///     A variable-length parameters list containing tag to expire linked cache
 ///     key.
 /// </param>
 public static void ExpireTag(params string[] tags)
 {
     foreach (var tag in tags)
     {
         List <string> list;
         if (CacheTags.TryRemove(CachePrefix + tag, out list))
         {
             foreach (var item in list)
             {
                 Cache.Remove(item);
             }
         }
     }
 }
コード例 #4
0
        /// <summary>Adds cache tags corresponding to a cached key in the CacheTags dictionary.</summary>
        /// <param name="cacheKey">The cache key.</param>
        /// <param name="tags">A variable-length parameters list containing tags corresponding to the <paramref name="cacheKey" />.</param>
        internal static void AddCacheTag(string cacheKey, params string[] tags)
        {
            foreach (var tag in tags)
            {
                CacheTags.AddOrUpdate(CachePrefix + tag, x => new List <string> {
                    cacheKey
                }, (x, list) =>
                {
                    if (!list.Contains(cacheKey))
                    {
                        list.Add(cacheKey);
                    }

                    return(list);
                });
            }
        }
コード例 #5
0
 /// <summary>Expire all cached keys linked to specified tags.</summary>
 /// <param name="tags">
 ///     A variable-length parameters list containing tag to expire linked cache
 ///     key.
 /// </param>
 public static void ExpireTag(params string[] tags)
 {
     foreach (var tag in tags)
     {
         List <string> list;
         if (CacheTags.TryRemove(CachePrefix + tag, out list))
         {
             // never lock something related to this list elsewhere or ensure we don't create a deadlock
             lock (list)
             {
                 foreach (var item in list)
                 {
                     Cache.Remove(item);
                 }
             }
         }
     }
 }
コード例 #6
0
        /// <summary>Adds cache tags corresponding to a cached key in the CacheTags dictionary.</summary>
        /// <param name="cacheKey">The cache key.</param>
        /// <param name="tags">A variable-length parameters list containing tags corresponding to the <paramref name="cacheKey" />.</param>
        internal static void AddCacheTag(string cacheKey, params string[] tags)
        {
            foreach (var tag in tags)
            {
                CacheTags.AddOrUpdate(CachePrefix + tag, x => new List <string> {
                    cacheKey
                }, (x, list) =>
                {
                    lock (list)
                    {
                        // never lock something related to this list elsewhere or ensure we don't create a deadlock
                        if (!list.Contains(cacheKey))
                        {
                            list.Add(cacheKey);
                        }
                    }

                    return(list);
                });
            }
        }
コード例 #7
0
        /// <summary>Expire all cached objects && tag.</summary>
        public static void ExpireAll()
        {
            var tags = CacheTags.Select(x => x.Key).ToList();

            // We do not use ExpireTag because type doesn't have CachePrefix
            foreach (var tag in tags)
            {
                List <string> list;
                if (CacheTags.TryRemove(tag, out list))
                {
                    // never lock something related to this list elsewhere or ensure we don't create a deadlock
                    lock (list)
                    {
                        foreach (var item in list)
                        {
                            Cache.Remove(item);
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: Cache1Demo.cs プロジェクト: noear/weed3_dotnet
        public static void demo_cache3()
        {
            DbContext       db    = DbConfig.pc_bcf;
            ICacheServiceEx cache = null;

            //1.缓存并添加简易标签
            db.call("user_get").set("xxx", 1)
            .caching(cache)
            .cacheTag("user_" + 1)
            .usingCache(60 * 1000)
            .getItem(new UserInfoModel());

            CacheTags tags = new CacheTags(cache);

            //2.1.可根据标签清除缓存
            tags.clear("user_" + 1);

            //2.2.可根据标签更新缓存
            tags.update <UserInfoModel>("user_" + 1, (m) => {
                m.name = "xxx";
                return(m);
            });
        }
コード例 #9
0
ファイル: WebCacheManager.cs プロジェクト: PhysicalEd/NFTB
        /// <summary>
        /// Clears all the items with this tag
        /// </summary>
        /// <param name="tag"></param>
        public void ClearTag(CacheTags cacheTag, dynamic id)
        {
            if (id == null)
            {
                id = "";
            }
            string tag          = cacheTag.ToString() + id;
            var    keysToRemove = new List <string>();

            foreach (DictionaryEntry item in System.Web.HttpRuntime.Cache)
            {
                if (!(item.Value is ICachable))
                {
                    continue;
                }
                var key = (ICachable)item.Value;
                if (key.Tags.Contains(tag))
                {
                    keysToRemove.Add(item.Key.ToString());
                }
            }

            // Remove each
            foreach (var cacheKey in keysToRemove)
            {
                try
                {
                    if (System.Web.HttpRuntime.Cache[cacheKey] != null)
                    {
                        System.Web.HttpRuntime.Cache.Remove(cacheKey);
                    }
                }
                catch
                {
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// Assigns this identifier to the tags property of the cache item
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="type"></param>
 /// <param name="identifier"></param>
 public static void AddTag(this ICachable cache, CacheTags type, dynamic identifier)
 {
     cache.Tags.Add(FormatTag(type, identifier));
 }
コード例 #11
0
 public void ClearTag(CacheTags tag, dynamic id)
 {
 }