mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 22:33:26 +08:00
59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
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);
|
|
}
|
|
}
|
|
|
|
} |