public bool Exist(string key) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} cahced.", _name)); } lock (_locker) { if (_ht.ContainsKey(key)) { WeakReference objWeak = (WeakReference)_ht[key]; if (null == objWeak || !objWeak.IsAlive || null == objWeak.Target) { _ht.Remove(key); return(false); } IAlbianCachedObject obj = (IAlbianCachedObject)objWeak.Target; if (((int)DateTime.Now.Subtract(obj.CreateTime).TotalSeconds) <= obj.Timespan) { if (_logger != null) { _logger.WarnFormat("key:{0} in {1} cached is expired.", key, _name); } return(true); } return(false); } return(false); } }
public void Set(string key, object value) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} chunk.", _name)); } lock (_locker) { if (_ht.ContainsKey(key)) { IAlbianChunkObject obj = new AlbianChunkObject { Key = key, Value = value, CreateTime = DateTime.Now }; _ht[key] = obj; } else { IAlbianChunkObject obj = new AlbianChunkObject { Key = key, Value = value, CreateTime = DateTime.Now }; _ht.Add(key, obj); } } }
public void Update(string key, object value, int seconds) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} cahced.", _name)); } if (0 >= seconds) { throw new ArgumentNullException("seconds", string.Format("seconds is less or eq 0 in the {0} cahced.", _name)); } lock (_locker) { if (!_ht.ContainsKey(key)) { throw new AlbianCachedException(string.Format("the {0} cached is not exist in the {1} cached.", key, _name)); } IAlbianCachedObject obj = new AlbianCachedObject { Timespan = seconds, Key = key, Value = value, CreateTime = DateTime.Now }; _ht[key] = WeakReferenceObject.CreateWeakReferenceObject(obj); } }
public void Insert(string key, object value, int seconds) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} cahced.", _name)); } if (0 >= seconds) { throw new ArgumentNullException("seconds", string.Format("seconds is less or eq 0 in the {0} cahced.", _name)); } lock (_locker) { if (_ht.ContainsKey(key)) { WeakReference objWeak = (WeakReference)_ht[key]; if (null == objWeak || !objWeak.IsAlive || null == objWeak.Target) { IAlbianCachedObject obj = new AlbianCachedObject { Timespan = seconds, Key = key, Value = value, CreateTime = DateTime.Now }; _ht[key] = WeakReferenceObject.CreateWeakReferenceObject(obj); } else { IAlbianCachedObject objOld = (IAlbianCachedObject)objWeak.Target; if (((int)DateTime.Now.Subtract(objOld.CreateTime).TotalSeconds) <= objOld.Timespan) { throw new AlbianCachedException(string.Format("the {0} cached is exist in the {1} cached.", key, _name)); } IAlbianCachedObject obj = new AlbianCachedObject { Timespan = seconds, Key = key, Value = value, CreateTime = DateTime.Now }; _ht[key] = WeakReferenceObject.CreateWeakReferenceObject(obj); } } else { IAlbianCachedObject obj = new AlbianCachedObject { Timespan = seconds, Key = key, Value = value, CreateTime = DateTime.Now }; _ht.Add(key, WeakReferenceObject.CreateWeakReferenceObject(obj)); } } }
public bool Exist(string key) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} chunk.", _name)); } lock (_locker) { return(_ht.ContainsKey(key)); } }
public void Remove(string key) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} cahced.", _name)); } lock (_locker) { if (_ht.ContainsKey(key)) { _ht.Remove(key); } } }
public object Get(string key) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} chunk.", _name)); } lock (_locker) { if (_ht.ContainsKey(key)) { IAlbianChunkObject obj = (IAlbianChunkObject)_ht[key]; return(obj.Value); } return(null); } }
protected override IList <ICacheGroup> ParserLocalGroups(XmlNodeList nodes) { if (ValidateService.IsNullOrEmpty(nodes)) { } IList <ICacheGroup> groups = new List <ICacheGroup>(); foreach (XmlNode node in nodes) { ICacheGroup group = ParserLocalGroup(node); if (null == group) { continue; } groups.Add(group); } return(groups); }
public void Update(string key, object value) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} chunk.", _name)); } lock (_locker) { if (!_ht.ContainsKey(key)) { throw new AlbianChunkException(string.Format("the {0} cached is not exist in the {1} chunk.", key, _name)); } IAlbianChunkObject obj = new AlbianChunkObject { Key = key, Value = value, CreateTime = DateTime.Now }; _ht[key] = obj; } }
public object Get(string key) { if (ValidateService.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", string.Format("key is null or empty in the {0} cahced.", _name)); } lock (_locker) { if (_ht.ContainsKey(key)) { WeakReference objWeak = (WeakReference)_ht[key]; if (null == objWeak || !objWeak.IsAlive || null == objWeak.Target) { _ht.Remove(key); return(null); } IAlbianCachedObject obj = (IAlbianCachedObject)objWeak.Target; return(((int)DateTime.Now.Subtract(obj.CreateTime).TotalSeconds) <= obj.Timespan ? obj.Value : null); ; } return(null); } }