Example #1
0
        public void Add(string key, object value, int expirationSeconds)
        {
            _cache.Add(key,
                       value,
                       new CacheItemPolicy
            {
                AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(expirationSeconds)
            });

            CacheItemInfo cacheItemInfo = null;

            if (_cacheInfo.TryGetValue(key, out cacheItemInfo))
            {
                cacheItemInfo.Misses++;
            }
            else
            {
                _cacheInfo.TryAdd(key, new CacheItemInfo {
                    Key    = key,
                    Type   = value.GetType().ToString(),
                    Hits   = 0,
                    Misses = 1
                });
            }
        }
Example #2
0
        public T Get <T>(string key)
        {
            CacheItemInfo cacheItemInfo = null;

            if (_cacheInfo.TryGetValue(key, out cacheItemInfo))
            {
                cacheItemInfo.Hits++;
                return((T)_cache[key]);
            }

            return(default(T));
        }