Пример #1
0
        public long GetCount()
        {
            var keyStoreFinalKey = LocalObjectCacheHelper.GetKeyStoreKey(this);

            if (CheckExisted(keyStoreFinalKey, true))
            {
                var keys = _cache.Get <List <string> >(keyStoreFinalKey);
                return(keys.Count);
            }
            else
            {
                return(0);
            }
        }
Пример #2
0
        public void RemoveFromCache(string key, bool isFullKey = false)
        {
            var cacheKey = GetFinalKey(key, isFullKey);

            _cache.Remove(cacheKey);

            //移除key
            var keyStoreFinalKey = LocalObjectCacheHelper.GetKeyStoreKey(this);

            if (CheckExisted(keyStoreFinalKey, true))
            {
                var keys = _cache.Get <List <string> >(keyStoreFinalKey);
                keys.Remove(cacheKey);
                _cache.Set(keyStoreFinalKey, keys);
            }
        }
Пример #3
0
        public IDictionary <string, object> GetAll()
        {
            IDictionary <string, object> data = new Dictionary <string, object>();
            //获取所有Key
            var keyStoreFinalKey = LocalObjectCacheHelper.GetKeyStoreKey(this);

            if (CheckExisted(keyStoreFinalKey, true))
            {
                var keys = _cache.Get <List <string> >(keyStoreFinalKey);
                foreach (var key in keys)
                {
                    data[key] = Get(key, true);
                }
            }
            return(data);
        }
Пример #4
0
        //public IContainerCacheStrategy ContainerCacheStrategy
        //{
        //    get { return LocalContainerCacheStrategy.Instance; }
        //}

        #region  步方法

        public void Set(string key, object value, TimeSpan?expiry = null, bool isFullKey = false)
        {
            if (key == null || value == null)
            {
                return;
            }

            var finalKey = base.GetFinalKey(key, isFullKey);

            var newKey = !CheckExisted(finalKey, true);

            if (expiry.HasValue)
            {
                _cache.Set(finalKey, value, expiry.Value);
            }
            else
            {
                _cache.Set(finalKey, value);
            }

            //由于MemoryCache不支持遍历Keys,所以需要单独储存
            if (newKey)
            {
                var           keyStoreFinalKey = LocalObjectCacheHelper.GetKeyStoreKey(this);
                List <string> keys;
                if (!CheckExisted(keyStoreFinalKey, true))
                {
                    keys = new List <string>();
                }
                else
                {
                    keys = _cache.Get <List <string> >(keyStoreFinalKey);
                }
                keys.Add(finalKey);
                _cache.Set(keyStoreFinalKey, keys);
            }
        }