示例#1
0
        } // Set

        /// <summary>
        /// Adds an item to the cache
        /// </summary>
        public void Set(string key, object value, TimeSpan timeSpan)
        {
            IDatabase cache = RedisConnection.GetDatabase();

            cache.StringSet(key, Serialize(value), timeSpan);

            // Clear the local cache on this server
            RuntimeCacheManager localCache = new RuntimeCacheManager();

            localCache.Remove(key);
        } // Set
示例#2
0
        } // Get

        /// <summary>
        /// Retrieves an item from the cache
        /// 1st tries the local cache (System.Runtime)
        ///   If found => okay
        ///   If not found => Get from central server and cache locally
        /// NOTE: Near Caching is used: This means we will bring items from a central distributed cache (Redis) to be
        /// cached on the local machine for short period of time so we do not have the overhead of the distributed cache call
        /// </summary>
        public object GetNearCache(string key, TimeSpan timeSpanForLocal)
        {
            RuntimeCacheManager localCache = new RuntimeCacheManager();
            object localCacheResult        = localCache.Get(key);

            if (localCacheResult != null)
            {
                return(localCacheResult);
            }
            else
            {
                IDatabase cache = RedisConnection.GetDatabase();
                object    centralCacheResult = Deserialize <object>(cache.StringGet(key));
                if (centralCacheResult != null)
                {
                    // cache locally
                    localCache.Set(key, centralCacheResult, timeSpanForLocal);
                }
                return(centralCacheResult);
            }
        } // Get