public ICacheResult Remove(string key) { CacheResult cacheResult = new CacheResult() { Success = false, Status = Status.None }; CacheResult cacheResult1 = cacheResult; try { SafeBucket instance = SafeBucket.Instance; try { IOperationResult operationResult = instance.Bucket.Remove(KeyGen.AttachPrefixToKey(key)); DebugUtil.CollectDebugInfo(string.Format("Remove('{0}'), Status:{1}, Exception:{2}", key, operationResult.Status, (operationResult.Exception == null ? "null" : operationResult.Exception.Message))); cacheResult1 = new CacheResult(operationResult); } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } } catch (Exception exception1) { Exception exception = exception1; cacheResult1.Exception = exception; DebugUtil.CollectDebugInfo(string.Format("Remove('{0}'), Exception:{1}", key, exception.Message)); } return(cacheResult1); }
public bool Exists(string key) { bool flag = false; try { SafeBucket instance = SafeBucket.Instance; try { flag = instance.Bucket.Exists(KeyGen.AttachPrefixToKey(key)); } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } DebugUtil.CollectDebugInfo(string.Format("Exists('{0}'), IsSuccess:{1}", key, flag)); } catch (Exception exception1) { Exception exception = exception1; DebugUtil.CollectDebugInfo(string.Format("Exists('{0}'), Exception:{1}", key, exception.Message)); } return(flag); }
public ICacheResult Remove(string key) { ICacheResult cacheResult; lock (Cache) { object obj = Cache.Remove(KeyGen.AttachPrefixToKey(key), null); cacheResult = new CacheResult(obj); } return(cacheResult); }
public ICacheResult <T> Set <T>(string key, T value, int expiredTime = 3600) { expiredTime = (expiredTime <= 0 ? 3600 : expiredTime); CacheItemPolicy cacheItemPolicy = new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddSeconds((double)expiredTime) }; lock (Cache) { Cache.Set(KeyGen.AttachPrefixToKey(key), cacheItemPolicy, null); } return(new CacheResult <T>()); }
public IDictionary <string, ICacheResult <T> > Get <T>(IList <string> keys) { object obj; Dictionary <string, ICacheResult <T> > strs = new Dictionary <string, ICacheResult <T> >(); keys = KeyGen.AttachPrefixToKey(keys); IDictionary <string, object> values = LocalCache.Cache.GetValues(keys, null); foreach (string key in keys) { obj = (values == null || !values.Keys.Contains(key) ? null : values[key]); strs.Add(KeyGen.DetachPrefixFromKey(key), new CacheResult <T>(obj)); } return(strs); }
public ICacheResult Remove(string key) { ICacheResult cacheResult = new CacheResult() { Success = false, Status = Status.None }; ICacheResult cacheResult1 = cacheResult; try { cacheResult1.Success = this.db.KeyDelete(KeyGen.AttachPrefixToKey(key), 0); cacheResult1.Status = (cacheResult1.Success ? Status.Success : Status.None); } catch (Exception exception) { cacheResult1.Exception = exception; } return(cacheResult1); }
public ICacheResult <T> Get <T>(string key) { CacheResult <T> cacheResult = new CacheResult <T>() { Success = false, Status = Status.None }; CacheResult <T> cacheResult1 = cacheResult; try { RedisValue redisValue = this.db.StringGet(KeyGen.AttachPrefixToKey(key), 0); cacheResult1.Value = JsonSerializerUtil.Deserialize <T>(redisValue); cacheResult1.Success = true; cacheResult1.Status = Status.Success; } catch (Exception exception) { cacheResult1.Exception = exception; } return(cacheResult1); }
public ICacheResult <T> Set <T>(string key, T value, int expiredTime = 3600) { CacheResult <T> cacheResult = new CacheResult <T>() { Success = false, Status = Status.None }; CacheResult <T> cacheResult1 = cacheResult; expiredTime = (expiredTime <= 0 ? 3600 : expiredTime); try { string str = JsonSerializerUtil.Serialize <T>(value); cacheResult1.Success = this.db.StringSet(KeyGen.AttachPrefixToKey(key), str, new TimeSpan?(new TimeSpan(0, 0, expiredTime)), 0, 0); cacheResult1.Status = Status.Success; } catch (Exception exception) { cacheResult1.Exception = exception; } return(cacheResult1); }
public ICacheResult <T> Get <T>(string key) { CacheResult <T> cacheResult = new CacheResult <T>() { Success = false, Status = Status.None }; CacheResult <T> cacheResult1 = cacheResult; try { SafeBucket instance = SafeBucket.Instance; try { IOperationResult <T> operationResult = instance.Bucket.Get <T>(KeyGen.AttachPrefixToKey(key)); object[] objArray = new object[] { key, operationResult.Status, null, null }; objArray[2] = (operationResult.Value == null ? "null" : operationResult.Value.ToString()); objArray[3] = (operationResult.Exception == null ? "null" : operationResult.Exception.Message); DebugUtil.CollectDebugInfo(string.Format("Get<T>('{0}'), Status:{1}, Value:{2}, Exception:{3}", objArray)); cacheResult1 = new CacheResult <T>(operationResult); } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } } catch (Exception exception1) { Exception exception = exception1; cacheResult1.Exception = exception; DebugUtil.CollectDebugInfo(string.Format("Get<T>('{0}'), Exception:{1}", key, exception.Message)); } return(cacheResult1); }
public ICacheResult <T> Set <T>(string key, T value, int expiredTime = 3600) { CacheResult <T> cacheResult = new CacheResult <T>() { Success = false, Status = Status.None }; CacheResult <T> cacheResult1 = cacheResult; expiredTime = (expiredTime <= 0 ? 3600 : expiredTime); try { SafeBucket instance = SafeBucket.Instance; try { IOperationResult <T> operationResult = instance.Bucket.Upsert <T>(KeyGen.AttachPrefixToKey(key), value, new TimeSpan(0, 0, 0, expiredTime)); DebugUtil.CollectDebugInfo(string.Format("Set<T>('{0}'), Status:{1}, Exception:{2}", key, operationResult.Status, (operationResult.Exception == null ? "null" : operationResult.Exception.Message))); cacheResult1 = new CacheResult <T>(operationResult); } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } } catch (Exception exception1) { Exception exception = exception1; cacheResult1.Exception = exception; DebugUtil.CollectDebugInfo(string.Format("Set<T>('{0}'), Exception:{1}", key, exception.Message)); } return(cacheResult1); }
public bool Exists(string key) { return(this.db.KeyExists(KeyGen.AttachPrefixToKey(key), CommandFlags.None)); }
private IDictionary <string, ICacheResult> RemoveKeys(string keyPrefix) { Dictionary <string, ICacheResult> strs = new Dictionary <string, ICacheResult>(); EndPoint[] endPoints = this.redis.GetEndPoints(false); for (int i = 0; i < (int)endPoints.Length; i++) { EndPoint endPoint = endPoints[i]; IServer server = this.redis.GetServer(endPoint, null); IEnumerable <RedisKey> redisKeys = server.Keys(this.db.Database, string.Concat(KeyGen.AttachPrefixToKey(keyPrefix), "*"), 10, (long)0, 0, 0); foreach (RedisKey redisKey in redisKeys) { string str = KeyGen.DetachPrefixFromKey(redisKey); strs.Add(str, this.Remove(str)); } } return(strs); }
public bool Exists(string key) { return(Cache.Contains(KeyGen.AttachPrefixToKey(key), null)); }
public IDictionary <string, ICacheResult <T> > Get <T>(IList <string> keys) { Dictionary <string, ICacheResult <T> > strs = new Dictionary <string, ICacheResult <T> >(); SafeBucket instance = SafeBucket.Instance; try { foreach (KeyValuePair <string, IOperationResult <T> > keyValuePair in instance.Bucket.Get <T>(KeyGen.AttachPrefixToKey(keys))) { strs.Add(KeyGen.DetachPrefixFromKey(keyValuePair.Key), new CacheResult <T>(keyValuePair.Value)); } } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } return(strs); }
public ICacheResult <T> Get <T>(string key) { object obj = Cache.Get(KeyGen.AttachPrefixToKey(key), null); return(new CacheResult <T>(obj)); }
public ICacheResult ResetKeys(string keyPrefix = "") { CacheResult cacheResult = new CacheResult() { Success = false, Status = Status.None }; CacheResult cacheResult1 = cacheResult; try { SafeBucket instance = SafeBucket.Instance; try { IBucket bucket = instance.Bucket; object[] appKey = new object[] { AppContext.AppKey, keyPrefix, SafeBucket.Instance.Bucket.Name, KeyGen.AttachPrefixToKey(keyPrefix) }; bucket.Query <object>(string.Format("CREATE INDEX {0}_{1}_KeyPrefix_Index ON {2}(position((meta().id), \"{3}\")) USING GSI", appKey)); IQueryResult <object> queryResult = instance.Bucket.Query <object>(string.Format("DELETE FROM {0} WHERE POSITION(META().id, \"{1}\") = 0", SafeBucket.Instance.Bucket.Name, KeyGen.AttachPrefixToKey(keyPrefix))); instance.Bucket.Query <object>(string.Format("DROP INDEX {0}.{1}_{2}_KeyPrefix_Index USING GSI", SafeBucket.Instance.Bucket.Name, AppContext.AppKey, keyPrefix)); DebugUtil.CollectDebugInfo(string.Format("Reset keys by prefix('{0}'), Status:{1}, Exception:{2}", keyPrefix, queryResult.Status, (queryResult.Exception == null ? "null" : queryResult.Exception.Message))); cacheResult1 = new CacheResult(queryResult); } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } } catch (Exception exception1) { Exception exception = exception1; cacheResult1.Exception = exception; DebugUtil.CollectDebugInfo(string.Format("Reset keys by prefix('{0}'), Exception:{1}", keyPrefix, exception.Message)); } return(cacheResult1); }
public IDictionary <string, ICacheResult <T> > Set <T>(IDictionary <string, T> items, int expiredTime = 3600) { Dictionary <string, ICacheResult <T> > strs = new Dictionary <string, ICacheResult <T> >(); expiredTime = (expiredTime <= 0 ? 3600 : expiredTime); TimeSpan timeSpan = new TimeSpan(0, 0, 0, expiredTime); SafeBucket instance = SafeBucket.Instance; try { foreach (KeyValuePair <string, T> item in items) { IOperationResult <T> operationResult = instance.Bucket.Upsert <T>(KeyGen.AttachPrefixToKey(item.Key), item.Value, timeSpan); DebugUtil.CollectDebugInfo(string.Format("Set<T>('{0}'), Status:{1}, Exception:{2}", item.Key, operationResult.Status, (operationResult.Exception == null ? "null" : operationResult.Exception.Message))); strs.Add(item.Key, new CacheResult <T>(operationResult)); } } finally { if (instance != null) { ((IDisposable)instance).Dispose(); } } return(strs); }