-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathMemoryCacheManager.cs
More file actions
43 lines (33 loc) · 1.1 KB
/
Copy pathMemoryCacheManager.cs
File metadata and controls
43 lines (33 loc) · 1.1 KB
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
using System.Collections;
using System.Reflection;
using Blog.Core.Common.Caches.Extensions;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
namespace Blog.Core.Common.Caches;
public class MemoryCacheManager : IMemoryCache
{
private readonly IOptions<MemoryCacheOptions> _optionsAccessor;
private MemoryCache _inner;
public MemoryCacheManager(IOptions<MemoryCacheOptions> optionsAccessor)
{
_optionsAccessor = optionsAccessor;
_inner = new MemoryCache(_optionsAccessor);
}
public void Dispose() => _inner.Dispose();
public ICacheEntry CreateEntry(object key) => _inner.CreateEntry(key);
public void Remove(object key) => _inner.Remove(key);
public bool TryGetValue(object key, out object value) => _inner.TryGetValue(key, out value);
public void Reset()
{
lock (_optionsAccessor)
{
var old = _inner;
_inner = new MemoryCache(_optionsAccessor);
old.Dispose();
}
}
public IEnumerable<string> GetAllKeys()
{
return _inner.GetKeys<string>();
}
}