【优化】移除EasyCaching.Core,EasyCaching.CSRedis,EasyCaching.InMemory等组件,直接使用原生CSRedis组件,替换SqlSugar二级缓存组件。

This commit is contained in:
程泰 孙
2023-04-03 15:29:52 +08:00
parent 8b7377de63
commit f1a72ac922
13 changed files with 370 additions and 295 deletions

View File

@@ -0,0 +1,59 @@
using SqlSugar;
using System;
using System.Collections.Generic;
namespace CoreCms.Net.Caching.SqlSugar
{
public class SqlSugarRedisCache : ICacheService
{
public SqlSugarRedisCache()
{
}
public void Add<TV>(string key, TV value)
{
RedisHelper.Set(key, value);
}
public void Add<TV>(string key, TV value, int cacheDurationInSeconds)
{
RedisHelper.Set(key, value, cacheDurationInSeconds);
}
public bool ContainsKey<TV>(string key)
{
return RedisHelper.Exists(key);
}
public TV Get<TV>(string key)
{
return RedisHelper.Get<TV>(key);
}
public IEnumerable<string> GetAllKey<TV>()
{
return RedisHelper.Keys("SqlSugarDataCache.*");
}
public TV GetOrCreate<TV>(string cacheKey, Func<TV> create, int cacheDurationInSeconds = int.MaxValue)
{
if (this.ContainsKey<TV>(cacheKey))
{
return this.Get<TV>(cacheKey);
}
else
{
var result = create();
this.Add(cacheKey, result, cacheDurationInSeconds);
return result;
}
}
public void Remove<TV>(string key)
{
RedisHelper.DelAsync(key);
}
}
}