first commit

This commit is contained in:
qianhao.xu
2024-09-23 09:14:22 +08:00
commit fdbe20be5a
407 changed files with 35117 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
using DOAN.Common.Cache;
namespace DOAN.ServiceCore.SqlSugar
{
/// <summary>
/// 数据库Redis缓存
/// </summary>
public class SqlSugarRedisCache : ICacheService
{
public void Add<V>(string key, V value)
{
RedisServer.Cache.Set(key, value);
}
public void Add<V>(string key, V value, int cacheDurationInSeconds)
{
RedisServer.Cache.Set(key, value, cacheDurationInSeconds);
}
public bool ContainsKey<V>(string key)
{
return RedisServer.Cache.Exists(key);
}
public V Get<V>(string key)
{
return RedisServer.Cache.Get<V>(key);
}
public IEnumerable<string> GetAllKey<V>()
{
return RedisServer.Cache.Keys("SqlSugarDataCache.*");
}
public V GetOrCreate<V>(string cacheKey, Func<V> create, int cacheDurationInSeconds = int.MaxValue)
{
if (ContainsKey<V>(cacheKey))
{
var result = Get<V>(cacheKey);
if (result == null)
{
return create();
}
else
{
return result;
}
}
else
{
var restul = create();
Add(cacheKey, restul, cacheDurationInSeconds);
return restul;
}
}
public void Remove<V>(string key)
{
RedisServer.Cache.Del(key);
}
}
}