lixiaojun
2022-07-27 96887ec041ba8ddb170c75c1492fc210735ecb37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;
        }
 
 
 
    }
}