using System;
using Microsoft.Extensions.Caching.Memory;
static readonly MemoryCache Cache = new MemoryCache(new MemoryCacheOptions());
///
/// 获取缓存中的值
///
/// 键
/// 值
public static object GetCacheValue(string key)
{
if (!string.IsNullOrEmpty(key) && Cache.TryGetValue(key, out var val))
{
return val;
}
return default(object);
}
///
/// 设置缓存
///
/// 键
/// 值
public static void SetCacheValue(string key, object value)
{
if (!string.IsNullOrEmpty(key))
{
Cache.Set(key, value, new MemoryCacheEntryOptions
{
SlidingExpiration = TimeSpan.FromHours(1)
});
}
}