public void Remove(Transaction.ITransactionLogger transaction) { if (Count == 0) { return; } var keys = new List <TKey>(); foreach (MruItem <TKey, TValue> itm in CacheCollection.Values) { if (itm.Transaction == transaction) { keys.Add(itm.Key); } } foreach (TKey o in keys) { MruItem <TKey, TValue> m = CacheCollection[o]; if (m != null && m.IndexToMruList != null) { mruManager.RemoveNode(m.IndexToMruList); } CacheCollection.Remove(o); } }
public Node <TKey, TValue> AddInHead(MruItem <TKey, TValue> data, bool addInCache) { var n = new Node <TKey, TValue>(data); this.AddInHead(n, addInCache); return(n); }
/// <summary> /// Save the unpersisted MRU items /// </summary> public virtual void Flush() { if ((SaveState & Sop.Mru.SaveTypes.CollectionSave) == Sop.Mru.SaveTypes.CollectionSave) { return; } SaveState |= Sop.Mru.SaveTypes.CollectionSave; if (CacheCollection.Count > 0) { const int batchLimit = 90; var dirtyNodes = new List <IInternalPersistent>(batchLimit); int batchCount = 0; foreach (Node <TKey, TValue> n in mruManager) { MruItem <TKey, TValue> itm = n.Data; if (itm.Value is IInternalPersistent) { if (((IInternalPersistent)itm.Value).IsDirty) { dirtyNodes.Add((IInternalPersistent)itm.Value); if (++batchCount > batchLimit) { if (mruManager.Collection != null) { if (dirtyNodes.Count > 0) { mruManager.Collection.OnMaxCapacity(dirtyNodes); mruManager.Collection.OnMaxCapacity(); } } dirtyNodes.Clear(); batchCount = 0; } } } else { break; } } if (mruManager.Collection != null) { if (dirtyNodes.Count > 0) { mruManager.Collection.OnMaxCapacity(dirtyNodes); mruManager.Collection.OnMaxCapacity(); } } } SaveState ^= Sop.Mru.SaveTypes.CollectionSave; }
internal MruItem <TKey, TValue> RemoveInTail(bool moveToRemoveList) { if (Count > 0 && (SaveState & Sop.Mru.SaveTypes.CollectionSave) != Sop.Mru.SaveTypes.CollectionSave) { MruItem <TKey, TValue> itm = mruManager.RemoveInTail(moveToRemoveList); if (itm != null && (typeof(TKey).IsValueType || itm.Key != null)) { CacheCollection.Remove(itm.Key); return(itm); } } return(null); }
public Node <TKey, TValue> AddInTail(MruItem <TKey, TValue> data) { Node <TKey, TValue> n = null; if (_tail == null) { return(AddInHead(data)); } n = new Node <TKey, TValue>(data); n.Previous = _tail; _tail.Next = n; _tail = n; Count++; return(n); }
public MruItem <TKey, TValue> RemoveInTail(bool moveToRemoveList) { if (_tail != null) { Count--; MruItem <TKey, TValue> d = _tail.Data; if (_tail.Previous != null) { _tail.Previous.Next = null; _tail = _tail.Previous; } else { _tail = null; _head = null; } if (d.Value is Sop.DataBlock) { //** check whether this needs to be supported.. //if (((DataBlock)d.Value).IsDirty) //{ // if (MoveToRemoveList && DataDriver != null && !RemovedObjects.ContainsKey(d.Value)) // RemovedObjects.Add(d.Value, d.Value); //} } else if (moveToRemoveList) { /*d.Value != null && 90;*/ if (!RemovedObjects.ContainsKey(d.Key)) { if (d.Value is IInternalPersistent) { if (((IInternalPersistent)d.Value).IsDirty) { RemovedObjects.Add(d.Key, d.Value); } } else { RemovedObjects.Add(d.Key, d.Value); } } } return(d); } return(null); }
/// <summary> /// Removes entry with key. /// </summary> /// <param name="key">key of entry to delete from collection</param> public virtual object Remove(TKey key) { MruItem <TKey, TValue> itm = CacheCollection[key]; if (itm != null) { if ((SaveState & Sop.Mru.SaveTypes.CollectionSave) != Sop.Mru.SaveTypes.CollectionSave) { if (itm.IndexToMruList != null) { mruManager.RemoveNode(itm.IndexToMruList); } CacheCollection.Remove(key); } } return(itm); }
public void AddInTail(TKey key, TValue value) { var itm = CacheCollection[key]; if (itm == null) { itm = new MruItem <TKey, TValue>(key, value, Transaction); } else { mruManager.RemoveNode(itm.IndexToMruList); itm.Transaction = Transaction; itm.Key = key; itm.Value = value; } itm.IndexToMruList = mruManager.AddInTail(itm); CacheCollection[key] = itm; }
/// <summary> /// Given a key, will return its value. /// If key is not found, will add a new entry having passed /// params key and value. /// </summary> public TValue this[TKey key] { get { MruItem <TKey, TValue> itm = this.CacheCollection[key]; if (itm == null) { return(default(TValue)); } if ((SaveState & Sop.Mru.SaveTypes.CollectionSave) != Sop.Mru.SaveTypes.CollectionSave) { if (itm.IndexToMruList != null) { mruManager.RemoveNode(itm.IndexToMruList); mruManager.AddInHead(itm.IndexToMruList, true); } } return(itm.Value); } set { if ((SaveState & Sop.Mru.SaveTypes.CollectionSave) == Sop.Mru.SaveTypes.CollectionSave) { return; } MruItem <TKey, TValue> itm = this.CacheCollection[key]; if (itm != null) { itm.Transaction = ((OnDisk.Algorithm.Collection.ICollectionOnDisk) this.mruManager.Collection).Transaction; mruManager.RemoveNode(itm.IndexToMruList); itm.Value = value; mruManager.AddInHead(itm.IndexToMruList, true); } else { Transaction = ((OnDisk.Algorithm.Collection.ICollectionOnDisk) this.mruManager.Collection).Transaction; this.Add(key, value); } } }
/// <summary> /// Add Object to the cache /// </summary> /// <param name="key"></param> /// <param name="value"></param> public virtual void Add(TKey key, TValue value) { if (SaveState != SaveTypes.Default) { return; } MruItem <TKey, TValue> itm = null; if (GeneratePruneEvent) { if (MaxCapacity > 0 && CacheCollection.Count >= MaxCapacity) { if (mruManager.RemovedObjects.Count == 0) { bool ogp = GeneratePruneEvent; GeneratePruneEvent = false; itm = mruManager.PeekInTail(); // prevent pruning to occur if itm is Specialized Store and is locked by a thread... if (!(itm.Value is SpecializedDataStore.SpecializedStoreBase && ((SpecializedDataStore.SpecializedStoreBase)(object) itm.Value).Locker.IsLocked)) { Log.Logger.Instance.Log(Log.LogLevels.Information, "GenericMruManager.Add: pruning enter."); for (int i = MaxCapacity; i > MinCapacity; i--) { itm = mruManager.RemoveInTail(mruManager.Collection != null); CacheCollection.Remove(itm.Key); if (!(itm.Value is IDisposable)) { continue; } if (itm.Value is SpecializedDataStore.SpecializedStoreBase) { if (((SpecializedDataStore.SpecializedStoreBase)(object) itm.Value).Locker.IsLocked) { continue; } ((SpecializedDataStore.SpecializedStoreBase)(object) itm.Value).InvokeFromMru = true; } if (mruManager.Collection == null) { ((IDisposable)itm.Value).Dispose(); } if (itm.Value is SpecializedDataStore.SpecializedStoreBase) { ((SpecializedDataStore.SpecializedStoreBase)(object) itm.Value).InvokeFromMru = false; } } Log.Logger.Instance.Log(Log.LogLevels.Information, "GenericMruManager.Add: pruning exit."); mruManager.SaveRemovedBlocks(); } GeneratePruneEvent = ogp; } } } itm = (MruItem <TKey, TValue>)Remove(key); if (itm == null) { itm = new MruItem <TKey, TValue>(key, value, Transaction); itm.IndexToMruList = mruManager.AddInHead(itm, false); } else { itm.Transaction = Transaction; itm.Key = key; itm.Value = value; mruManager.AddInHead(itm.IndexToMruList, true); } CacheCollection[key] = itm; }
public Node <TKey, TValue> AddInHead(MruItem <TKey, TValue> data) { return(AddInHead(data, false)); }