Esempio n. 1
0
        void ClearCache(string cacheType)
        {
            if (cacheType == "me")
            {
                _cache.Remove(CacheKey());
                nbWarning.Text = string.Format(
                    "Your cache key has been cleared. Click <a href=\"{0}\">here</a> to reload the page.",
                    new PageReference(RockPage.PageId).BuildUrl());
            }
            else if (cacheType == "block")
            {
                string key  = BlockCacheKey();
                var    keys = _cache.Where(kvp => kvp.Key.StartsWith(key)).Select(kvp => kvp.Key).ToList();

                foreach (var k in keys)
                {
                    _cache.Remove(k);
                }

                nbWarning.Text = string.Format(
                    "{1} cache keys have been cleared. Click <a href=\"{0}\">here</a> to reload the page.",
                    new PageReference(RockPage.PageId).BuildUrl(),
                    keys.Count);
            }
            else
            {
                nbWarning.Text = "Cannot clear cache, unknown cache type.";
            }
        }
Esempio n. 2
0
        /// <summary>
        ///   Gets all cache items or the ones in a partition, if specified. If an item is a
        ///   "sliding" or "static" value, its lifetime will be increased by corresponding interval.
        /// </summary>
        /// <param name="partition">The optional partition.</param>
        /// <typeparam name="TVal">The type of the expected values.</typeparam>
        /// <returns>All cache items.</returns>
        protected override IList <ICacheItem <TVal> > GetItemsInternal <TVal>(string partition)
        {
            // Pick only the items with the right type.
            var q = _store.Where(x => x.Value is CacheValue).Select(x => new
            {
                CacheKey   = DeserializeCacheKey(x.Key),
                CacheValue = x.Value as CacheValue
            });

            // If partition has been specified, then we shall also filter by it.
            if (partition != null)
            {
                q = q.Where(x => x.CacheKey.Partition == partition);
            }

            // Project the items to proper KVLite cache items.
            return(q.Select(x => DeserializeCacheItem <TVal>(x.CacheValue, x.CacheKey.Partition, x.CacheKey.Key).Value).ToArray());
        }