コード例 #1
0
        /// <summary>
        /// Remove a named item from the cache.
        /// </summary>
        /// <param name="key">Key for item to remove</param>
        public static void Remove(object key)
        {
            Verify.ArgumentNotNull(key, "key");

            var context = HttpContext.Current;

            if (context != null)
            {
                context.Items.Remove(key);
            }
            else
            {
                FallbackCache.Remove(key);
            }
        }
コード例 #2
0
        /// <summary>
        /// 删除值
        /// </summary>
        public void Remove(TKey key)
        {
            // 先从备用的缓存删除
            FallbackCache.Remove(key);
            // 尝试序列化key
            string keyJson;

            try {
                keyJson = JsonConvert.SerializeObject(key);
            } catch {
                SerializeFailedTypes[typeof(TKey)] = true;
                return;
            }
            // 从Redis删除
            var db = RedisConnectionFactory.GetDatabase();

            db.KeyDelete(UniquePrefix + keyJson);
        }