mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-05-07 16:07:21 +08:00
【优化】移除EasyCaching.Core,EasyCaching.CSRedis,EasyCaching.InMemory等组件,直接使用原生CSRedis组件,替换SqlSugar二级缓存组件。
This commit is contained in:
59
CoreCms.Net.Caching/SqlSugar/SqlSugarRedisCache.cs
Normal file
59
CoreCms.Net.Caching/SqlSugar/SqlSugarRedisCache.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user