using SqlSugar; using System; using System.Collections.Generic; namespace CoreCms.Net.Caching.SqlSugar { public class SqlSugarRedisCache : ICacheService { public SqlSugarRedisCache() { } public void Add(string key, TV value) { RedisHelper.Set(key, value); } public void Add(string key, TV value, int cacheDurationInSeconds) { RedisHelper.Set(key, value, cacheDurationInSeconds); } public bool ContainsKey(string key) { return RedisHelper.Exists(key); } public TV Get(string key) { return RedisHelper.Get(key); } public IEnumerable GetAllKey() { return RedisHelper.Keys("SqlSugarDataCache.*"); } public TV GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = int.MaxValue) { if (this.ContainsKey(cacheKey)) { return this.Get(cacheKey); } else { var result = create(); this.Add(cacheKey, result, cacheDurationInSeconds); return result; } } public void Remove(string key) { RedisHelper.DelAsync(key); } } }