Yuebon.NetCore/Yuebon.Commons/Cache/MemoryCacheService.cs
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Microsoft.Extensions.Caching.Memory;
using System.Collections;
using System.Reflection;
using System.Runtime.Caching;
using System.Text.RegularExpressions;
namespace Yuebon.Commons.Cache;
/// <summary>
/// MemoryCache缓存操作
/// </summary>
public class MemoryCacheService : ICacheService
{
/// <summary>
///
/// </summary>
private readonly IMemoryCache _cache= new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptions());
#region 验证缓存项是否存在
/// <summary>
/// 验证缓存项是否存在,TryGetValue 来检测 Key是否存在的
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public bool Exists(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
object cached;
return _cache.TryGetValue(key, out cached);
}
#endregion
#region 添加缓存
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
/// <returns></returns>
public bool Add(string key, object value)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_cache.Set(key, value);
return Exists(key);
}
/// <summary>
/// 添加缓存
后面还有 294 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。