예제 #1
0
        private ApiResponse <T> ReadFromCache <T>(CacheInfo cacheInfo)
        {
            var response = new ApiResponse <T>();

            if (cacheInfo.Read)
            {
                if (cacheInfo.IsSerialized)
                {
                    response = _serializer.Deserialize <T>(_cache.Get <string>(cacheInfo.CacheKey).Data); //todo handle error
                }
                else
                {
                    response = _cache.Get <T>(cacheInfo.CacheKey);
                }
            }
            return(response);
        }
예제 #2
0
        public IActionResult GetAppCache(string cacheKey)
        {
            var value = _appCache.Get <string>(cacheKey);
            var obj   = new TestCache()
            {
                CacheKey = cacheKey, Value = value
            };
            var x = new ObjectResult(obj);

            return(x);
        }
        public async Task <bool> IsTokenBlacklisted(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(false);
            }

            var cacheKey    = GetCacheKey(token);
            var cachedValue = await _cache.Get(cacheKey);

            return(cachedValue is object);
        }
예제 #4
0
        //-----------------------------------------------------------

        internal IList getListFromCache(String queryKey, Type t)
        {
            if (CacheTime.isListUpdate(queryKey, t))
            {
                return(null);
            }

            List <int> ids = appCache.Get(queryKey) as List <int>;

            if (ids == null)
            {
                return(null);
            }

            IList result = new ArrayList();

            foreach (int id in ids)
            {
                IEntity obj = this.findOnePrivate(t, id);

                if (obj == null)
                {
                    return(null);
                }

                if (CacheTime.isObjectUpdated(obj))
                {
                    return(null);                                  // 如果有任何一个对象更新过,则缓存失效
                }
                // 检查实体属性
                renewEntityPropertyValue(obj);

                result.Add(obj);
            }


            logger.Debug("APP_cache_get=>" + queryKey);
            return(result);
        }
예제 #5
0
        public virtual void Read()
        {
            String key = ctx.web.param("key");

            if (strUtil.IsNullOrEmpty(key))
            {
                echoToParentPart("cache key 不能为空");
                return;
            }

            Object val        = _appCache.Get(key);
            String cacheValue = val == null ? "" : val.ToString();

            if (key.StartsWith("__object_"))
            {
                cacheValue = Json.ToString(val as IEntity);
            }

            set("cacheValue", strUtil.EncodeTextarea(cacheValue));
            set("cacheKey", key);

            target(Update);
        }
        public ApiResponse <string> GetAppCache()
        {
            var value = _appCache.Get <string>("test");

            return(value);
        }