using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace IStation
|
{
|
internal sealed partial class SharedMemoryCache
|
{
|
/// <summary>
|
/// Remove items from cache where a supplied function returns true for any given key
|
/// </summary>
|
/// <param name="keyFunction">function to test a string cache key, and return true if it should be removed from cache</param>
|
public void Remove(Func<string, bool> keyFunction)
|
{
|
if (this._isWiping) { return; }
|
|
foreach (string key in GetKeys())
|
{
|
if (keyFunction != null && keyFunction(key))
|
{
|
this.Remove(key);
|
}
|
}
|
}
|
|
/// <summary>
|
/// Remove an item from cache
|
/// </summary>
|
/// <param name="key">the key to the item to remove</param>
|
public void Remove(string key)
|
{
|
if (this._isWiping || key == null) { return; }
|
|
((IMemoryCacheDirect)this).Remove(key);
|
}
|
|
/// <summary>
|
/// The core method that direcly removes an item from the wrapped memory cache
|
/// </summary>
|
/// <param name="key">key of cache item to remove</param>
|
void IMemoryCacheDirect.Remove(string key)
|
{
|
if (this._isWiping || key == null) { return; }
|
|
this._memoryCache.Remove(key);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="keys"></param>
|
/// <returns></returns>
|
public int Remove(IEnumerable<string> 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;
|
}
|
|
|
|
}
|
}
|