public override void Set(string key, byte[] value, int minutes) { #if !(NETCORE || CORE) _memoryCache.Set(key, value, _cacheItemPolicy); #else Microsoft.Extensions.Caching.Memory.ICacheEntry cacheEntry = _memoryCache.CreateEntry(key); cacheEntry.SlidingExpiration = TimeSpan.FromMinutes(this.minutes); cacheEntry.Value = value; #endif }
/// <summary> /// 添加缓存 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="expiry">过期时间</param> /// <returns></returns> public bool Add(string key, object value, TimeSpan?expiry = null) { #if net40 var cachePolicy = new System.Runtime.Caching.CacheItemPolicy(); if (expiry.HasValue) { cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.Add(expiry.Value); } var item = new System.Runtime.Caching.CacheItem(key, value); Cache.Set(item, cachePolicy); #endif #if netstandard2_0 using (var entry = Cache.CreateEntry(key)) { entry.Value = value; entry.AbsoluteExpirationRelativeToNow = expiry; } #endif return(true); }