using SqlSugar; using System; using System.Collections.Generic; using HT.Cloud.Code; namespace HT.Cloud.DataBase { public class SqlSugarCache : ICacheService { public void Add(string key, TV value) { CacheHelper.SetBySecond(key, value); } public void Add(string key, TV value, int cacheDurationInSeconds) { CacheHelper.SetBySecond(key, value, cacheDurationInSeconds); } public bool ContainsKey(string key) { return CacheHelper.Exists(key); } public TV Get(string key) { return CacheHelper.Get(key); } public IEnumerable GetAllKey() { return CacheHelper.GetAllKey(); } 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) { CacheHelper.Remove(key); } } }