Beispiel #1
0
        public T Get <T>(string key)
        {
            var result = _localCacher.Get <T>(key);

            if (result != null)
            {
                return(result);
            }
            result = _remoteCacher.Get <T>(key);
            if (result != null)
            {
                var ttl       = _remoteCacher.TimeToLive(key);
                var parentKey = _remoteCacher.Get <string>(key + ".parent");
                if (parentKey != null)
                {
                    parentKey = parentKey.Substring(_cacheSleeve.KeyPrefix.Length);
                }
                if (ttl > -1)
                {
                    _localCacher.Set(key, result, TimeSpan.FromSeconds(ttl), parentKey);
                }
                else
                {
                    _localCacher.Set(key, result, parentKey);
                }
                result = _localCacher.Get <T>(key);
            }
            return(result);
        }
Beispiel #2
0
        public T Get <T>(string key)
        {
            var result = _localCacher.Get <T>(key);

            if (result != null)
            {
                return(result);
            }
            result = _remoteCacher.Get <T>(key);
            if (result != null)
            {
                var ttl       = (int)_remoteCacher.TimeToLive(key);
                var parentKey = _remoteCacher.Get <string>(key + ".parent");
                if (ttl > -1)
                {
                    _localCacher.Set(key, result, TimeSpan.FromSeconds(ttl), _cacheSleeve.StripPrefix(parentKey));
                }
                else
                {
                    _localCacher.Set(key, result, _cacheSleeve.StripPrefix(parentKey));
                }
                result = _localCacher.Get <T>(key);
            }
            return(result);
        }