using System; using System.Collections.Generic; using System.Linq; namespace IStation { internal sealed partial class SharedMemoryCache { /// /// Remove items from cache where a supplied function returns true for any given key /// /// function to test a string cache key, and return true if it should be removed from cache public void Remove(Func keyFunction) { if (this._isWiping) { return; } foreach (string key in GetKeys()) { if (keyFunction != null && keyFunction(key)) { this.Remove(key); } } } /// /// Remove an item from cache /// /// the key to the item to remove public void Remove(string key) { if (this._isWiping || key == null) { return; } ((IMemoryCacheDirect)this).Remove(key); } /// /// The core method that direcly removes an item from the wrapped memory cache /// /// key of cache item to remove void IMemoryCacheDirect.Remove(string key) { if (this._isWiping || key == null) { return; } this._memoryCache.Remove(key); } /// /// /// /// /// public int Remove(IEnumerable keys) { if (this._isWiping || keys == null || keys.Count() == 0) { return 0; } int num = 0; foreach (var key in keys) { this._memoryCache.Remove(key); num++; } return num; } public int Remove_StartWith(string key) { if (this._isWiping || key == null) { return 0; } var keys = GetKeys(); int num = 0; foreach (var cacheKey in keys.Where(x => x.StartsWith(key))) { _memoryCache.Remove(cacheKey); num++; } return num; } } }