using Furion; using Furion.DependencyInjection; using SqlSugar; using System; using System.Collections.Generic; namespace Myshipping.Core; public class SqlSugarCache : ICacheService { private static ICache _cache = App.GetOptions().CacheType == CacheType.MemoryCache? App.RootServices.GetService(typeof(MemoryCache)) as ICache : App.RootServices.GetService(typeof(RedisCache)) as ICache; public void Add(string key, TV value) { _cache.Set(key, value); } public void Add(string key, TV value, int cacheDurationInSeconds) { _cache.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds)); } public bool ContainsKey(string key) { return _cache.Exists(key); } public TV Get(string key) { return _cache.Get(key); } public IEnumerable GetAllKey() { return _cache.GetAllKeys(); } 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) { _cache.Del(key); } }