using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; namespace Ropin.Core.Common { /// /// 实例化缓存接口ICaching /// public class MemoryCaching : ICaching { //引用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)); } } }