移动系统liao
2024-09-23 78028cee453a5878835a27f884ae36c0900fe8f7
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
using Microsoft.Extensions.Caching.Memory;
using System;
 
namespace CoreCms.Net.Caching.AutoMate.MemoryCache
{
    /// <summary>
    /// 实例化缓存接口ICaching
    /// </summary>
    public class MemoryCaching : ICachingProvider
    {
        //引用Microsoft.Extensions.Caching.Memory;这个和.net 还是不一样,没有了Httpruntime了
        private readonly IMemoryCache _cache;
        //还是通过构造函数的方法,获取
        public MemoryCaching(IMemoryCache cache)
        {
            _cache = cache;
        }
 
        public object Get(string cacheKey)
        {
            return _cache.Get(cacheKey);
        }
 
        public void Set(string cacheKey, object cacheValue, int timeSpan)
        {
            _cache.Set(cacheKey, cacheValue, TimeSpan.FromSeconds(timeSpan * 60));
        }
    }
 
}