private T GetObject() { // select redis var redisClient = RedisFacade.GetRedis("redis_cache"); var cachedItem = redisClient.StringGet(CacheKey); if (cachedItem.IsNullOrEmpty && _loader != null) { lock (_loaderLock) { var resultPreviousLoaded = redisClient.StringGet(CacheKey); if (resultPreviousLoaded.HasValue) { return(JsonConvert.DeserializeObject <T>(cachedItem)); } cachedItem = _loader(); #if RELEASE // insert redis redisClient.StringSet(CacheKey, cachedItem, _expireSpan); #endif } } return(cachedItem.IsNullOrEmpty ? null : JsonConvert.DeserializeObject <T>(cachedItem)); }
public void SetCachedObject(string value) { lock (_loaderLock) { // select redis var redisClient = RedisFacade.GetRedis("redis_cache"); // delete exist data redisClient.KeyDelete(CacheKey); // insert redis redisClient.StringSet(CacheKey, value, _expireSpan); } }