/// <summary> /// overrides, supplies the default condition /// </summary> /// <param name="bag"></param> public override void Commit(ICommitBag cb) { lock (this._stateLock) { //commit first. if it kacks we don't do anything base.Commit(cb); //build and commit the conditions CommitBag conditionCommitBag = new CommitBag(); //foreach add, register a condition if (this.ExpirableFactory != null) { cb.ItemsToSave.WithEach(x => { //generate the eviction condition var evictionConditionLogic = this.ExpirableFactory.Perform(x) as LogicOfTo<IHasId, IExpirable>; //save the eviction condition in the eviction store, keyed by the storedobjectid of the item to save var conditionToSave = x.GetStoredObjectId().BuildAsId().HasContext(evictionConditionLogic.Result); //var soid = conditionToSave.GetStoredObjectId(); //var soid2 = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x.GetStoredObjectId()); //bool isEq = soid.Equals(soid2); conditionCommitBag.MarkItemSaved(conditionToSave); }); } //foreach remove, remove a condition cb.ItemsToDelete.WithEach(x => { var delId = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x); conditionCommitBag.MarkItemDeleted(delId); }); this.ExpirableStore.Commit(conditionCommitBag); } }
/// <summary> /// registers an item with a specific eviction condition. If the condition is mutable, every touch/get of the item will result /// in a condition mutation. /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="evictionCondition">may be null</param> public virtual void Commit(ICommitBag cb, IExpirable evictionCondition) { lock (this._stateLock) { //commit first. if it kacks we don't do anything this.Decorated.Commit(cb); //build and commit the conditions CommitBag conditionCommitBag = new CommitBag(); //foreach add, register a condition cb.ItemsToSave.WithEach(x => { //save the eviction condition in the eviction store, keyed by the storedobjectid of the item to save var conditionToSave = x.GetStoredObjectId().BuildAsId().HasContext(evictionCondition); conditionCommitBag.MarkItemSaved(conditionToSave); }); //foreach remove, remove a condition cb.ItemsToDelete.WithEach(x => { var delId = StoredObjectId.New(typeof(ContextualIHasIdDecoration), x); conditionCommitBag.MarkItemDeleted(delId); }); this.ExpirableStore.Commit(conditionCommitBag); } }