using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CoreCms.Net.Caching.Redis; using StackExchange.Redis; using CoreCms.Net.Configuration; namespace CoreCms.Net.Caching.SqlSugar { public class SqlSugarRedisCache : ICacheService { //readonly RedisCacheManager _service = null; static readonly RedisCacheManager _service = new RedisCacheManager(); public SqlSugarRedisCache() { //_service = new RedisCacheManager(); ; } public void Add(string key, TV value) { _service.Set(key, value); } public void Add(string key, TV value, int cacheDurationInSeconds) { _service.Set(key, value, cacheDurationInSeconds); } public bool ContainsKey(string key) { return _service.Exists(key); } public TV Get(string key) { return _service.Get(key); } public IEnumerable GetAllKey() { return _service.SearchCacheRegex("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) { _service.Remove(key); } } }