namespace Admin.NET.Core;
///
/// SqlSugar二级缓存
///
public class SqlSugarCache : ICacheService
{
private static readonly ICache _cache = App.GetService(typeof(ICache)) as ICache;
public void Add(string key, V value)
{
_cache.Set(key, value);
}
public void Add(string key, V value, int cacheDurationInSeconds)
{
_cache.Set(key, value, cacheDurationInSeconds);
}
public bool ContainsKey(string key)
{
return _cache.ContainsKey(key);
}
public V Get(string key)
{
return _cache.Get(key);
}
public IEnumerable GetAllKey()
{
return _cache.Keys;
}
public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = int.MaxValue)
{
if (!_cache.TryGetValue(cacheKey, out V value))
{
value = create();
_cache.Set(cacheKey, value, cacheDurationInSeconds);
}
return value;
}
public void Remove(string key)
{
_cache.Remove(key);
}
}