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 static void Init_Redis(params RedisConfigurationSection[] configurations) { foreach (var ridisConfig in configurations) { RedisFacade.AddConnection(ridisConfig); } }
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); } }