private void SetInternalData(Guid guid, T data, DateTime date) { lock (dictionary) { dictionary[guid] = new DatedObject() { Data = data, FileDate = date }; } if (data is IPersistableChangeNotifiable) { (data as IPersistableChangeNotifiable).OnChanged(); } }
} //put() public object get(string Name) { object ReturnVal = null; Object Object = null; string Key = string.Empty; try { _ReaderWriterLockSlim.EnterReadLock(); Key = _makeRealKey(Name); Object = _Cache.Get(Key); }//try finally { _ReaderWriterLockSlim.ExitReadLock(); } if (null != Object) { DatedObject DatedObject = (DatedObject)Object; if (DatedObject.DateTime >= CacheDirtyThreshold) { ReturnVal = DatedObject.Object; } else { try { _ReaderWriterLockSlim.EnterWriteLock(); _Cache.Remove(Key); //ReturnVal will be null by default } finally { _ReaderWriterLockSlim.ExitWriteLock(); } } //if-else the object is stale } //if there is an object for that key return(ReturnVal); }
}//delete() public void put(string Name, object Object) { if (null != Object) { DatedObject DatedObject = new DatedObject(); DatedObject.Object = Object; DatedObject.DateTime = DateTime.Now; try { _ReaderWriterLockSlim.EnterWriteLock(); string Key = _makeRealKey(Name); _Cache.Add(Key, DatedObject, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } finally { _ReaderWriterLockSlim.ExitWriteLock(); } } //if object is not null } //put()