/// <summary> /// 清空所有缓存 /// </summary> public void FlushAllCache() { if (CacheStorageManager.IsExist(CachingConst.GetQueryCacheKeysCacheKey(DbContext.DataBaseName), out HashSet <string> keys)) { foreach (var item in keys) { CacheStorageManager.Delete(item); } } }
/// <summary> /// 构建sql查询缓存的总key /// </summary> /// <returns></returns> private string GetQueryCacheKey(string collectionName = null) { string key = $"{CachingConst.CacheKey_QueryCache}{collectionName ?? DbContext.CollectionName}"; //缓存键更新 if (!CacheStorageManager.IsExist(CachingConst.GetQueryCacheKeysCacheKey(DbContext.DataBaseName), out HashSet <string> keys)) { keys = new HashSet <string>(); } keys.Add(key); CacheStorageManager.Put(CachingConst.GetQueryCacheKeysCacheKey(DbContext.DataBaseName), keys, CacheOptions.MaxExpiredTimeSpan); return(key); }