添加项目文件。

This commit is contained in:
JianWeie
2021-12-20 21:27:32 +08:00
parent 747486f5cb
commit 82d825b7a5
3514 changed files with 887941 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Redis;
using StackExchange.Redis;
using CoreCms.Net.Configuration;
namespace CoreCms.Net.Caching.SqlSugar
{
public class SqlSugarRedisCache : ICacheService
{
readonly RedisCacheManager _service = null;
public SqlSugarRedisCache()
{
_service = new RedisCacheManager(); ;
}
public void Add<TV>(string key, TV value)
{
_service.Set(key, value);
}
public void Add<TV>(string key, TV value, int cacheDurationInSeconds)
{
_service.Set(key, value, cacheDurationInSeconds);
}
public bool ContainsKey<TV>(string key)
{
return _service.Exists(key);
}
public TV Get<TV>(string key)
{
return _service.Get<TV>(key);
}
public IEnumerable<string> GetAllKey<TV>()
{
return _service.SearchCacheRegex("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)
{
_service.Remove(key);
}
}
}