private string _Get(Areas area, string field, string key) { key = EncodeBlobName(key); var blob = GetBlobReference(area, field, key); if (!blob.Exists()) { return(null); } var tmp = blob.DownloadText(); VigilCacheData vcd = VigilCacheData.FromString(tmp); if (vcd.ExpirationDate < DateTime.UtcNow) { blob.Delete(); return(null); } string result = null; if (Compression.IsBase64String(tmp)) { result = Compression.Decompress(vcd.Value); } else { result = vcd.Value; } return(result); }
private string _Get(Areas area, string field, string key) { key = EncodeBlobName(key); var redisKey = string.Format("{0}^{1}^{2}", area.ToString(), field, key); IDatabase cache = lazyConnection.Value.GetDatabase(); if (cache.KeyExists(redisKey)) { var tmp = cache.StringGet(redisKey); VigilCacheData vcd = VigilCacheData.FromString(tmp); if (vcd != null && vcd.ExpirationDate < DateTime.UtcNow) { cache.KeyDelete(redisKey); return(null); } string result = null; if (Compression.IsBase64String(tmp)) { result = Compression.Decompress(vcd.Value); } else { result = vcd.Value; } return(result); } return(null); }
private T _Get <T>(Areas area, string field, string key) { key = EncodeBlobName(key); var blob = GetBlobReference(area, field, key); if (!blob.Exists()) { return(default(T)); } string json = ""; try { var tmp = blob.DownloadText(); VigilCacheData vcd = VigilCacheData.FromString(tmp); if (vcd.ExpirationDate < DateTime.UtcNow) { blob.Delete(); return(default(T)); } if (Compression.IsBase64String(vcd.Value)) { json = Compression.Decompress(vcd.Value); } else { json = vcd.Value; } } catch (Exception ex) { Trace.TraceError("Could not retrieve cache object for key {0}. {1}", key, ex.Message); return(default(T)); } if (!string.IsNullOrEmpty(json)) { try { return(JsonConvert.DeserializeObject <T>(json)); } catch (Exception ex) { Trace.TraceError("Could not deserialize cache object for key {0}. {1}", key, ex.Message); } } return(default(T)); }
private T _Get <T>(Areas area, string field, string key) { key = EncodeBlobName(key); var redisKey = string.Format("{0}^{1}^{2}", area.ToString(), field, key); IDatabase cache = lazyConnection.Value.GetDatabase(); string json = ""; if (cache.KeyExists(redisKey)) { var tmp = cache.StringGet(redisKey); VigilCacheData vcd = VigilCacheData.FromString(tmp); if (vcd == null || vcd.ExpirationDate < DateTime.UtcNow) { cache.KeyDelete(redisKey); return(default(T));; } if (Compression.IsBase64String(vcd.Value)) { json = Compression.Decompress(vcd.Value); } else { json = vcd.Value; } } if (!string.IsNullOrEmpty(json)) { try { return(JsonConvert.DeserializeObject <T>(json)); } catch (Exception ex) { Trace.TraceError("Could not deserialize cache object for key {0}. {1}", key, ex.Message); } } return(default(T)); }