using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace DocumentServiceAPI.Core
|
{
|
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);
|
}
|
}
|
}
|