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
using Microsoft.Extensions.Caching.Memory;
namespace IStation
{
    internal sealed partial class SharedMemoryCache
    {
        /// <summary>
        /// Queries key in cache for object of type T
        /// </summary>
        /// <typeparam name="T">type of object expected</typeparam>
        /// <param name="key">key to the cache item to get</param>
        /// <returns>an object from cache of type T, else default(T)</returns>
        public T Get<T>(string key)
        {
            return this.Get<T>(key, out _);
        }
 
        /// <summary>
        /// Queries key in cache for object of type T
        /// </summary>
        /// <typeparam name="T">type of object expected</typeparam>
        /// <param name="key">key to the cache item to get</param>
        /// <param name="found">output parameter, indicates whether the return value was found in the cache and of the expected type</param>
        /// <returns>an object from cache of type T, else default(T)</returns>
        public T Get<T>(string key, out bool found)
        {
            object value = this.Get(key);
 
            if (value is T)
            {
                found = true;
                return (T)value;
            }
 
            found = false;
            return default(T);
        }
 
        /// <summary>
        /// Wrapper
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public object Get(string key)
        {
            if (key == null)
                return default;
            return _memoryCache.Get(key);
        }
 
    }
}