RMS.Common/Tools/LocalCache.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;
namespace RMS.Common.Tools
{
/// <summary>
/// 本地缓存
/// </summary>
public class LocalCache
{
private static readonly ObjectCache Cache;
static LocalCache()
{
Cache = MemoryCache.Default;
}
private static DateTimeOffset GetTimeOffset(int seconds)
{
return seconds <= 0 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.AddSeconds(seconds);
}
public bool Add(string key, string value, int seconds = 0)
{
return !value.IsNullOrEmpty() && Cache.Add(key, value, GetTimeOffset(seconds));
}
public bool Add<T>(string key, T value, int seconds = 0) where T : class, new()
{
return Add(key, value.ToJson(), seconds);
}
public bool Set(string key, string value, int seconds = 0)
{
if (value.IsNullOrEmpty())
return false;
Cache.Set(key, value, GetTimeOffset(seconds));
return true;
}
public bool Set<T>(string key, T value, int seconds = 0) where T : class, new()
{
if (value.IsNull())
return false;
Set(key, value.ToJson(), seconds);
return true;
}
public string Get(string key)
{
return Get<string>(key);
}
后面还有 72 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。