From 290578d8243a3d13e32f3d9c17debf9bbbab5275 Mon Sep 17 00:00:00 2001
From: hang <872297557@qq.com>
Date: Fri, 13 Oct 2023 11:34:55 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E7=94=A8=E7=9A=84?=
=?UTF-8?q?=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Service/Management/UserService.cs | 1 -
.../IRaCIS.Core.Domain.Share.csproj | 4 +
IRaCIS.Core.Infrastructure/Cache/CacheType.cs | 18 ---
IRaCIS.Core.Infrastructure/Cache/ICache.cs | 107 ---------------
.../Cache/MemoryCache.cs | 127 ------------------
.../Cache/RedisCache.cs | 88 ------------
.../IRaCIS.Core.Infrastructure.csproj | 2 +-
7 files changed, 5 insertions(+), 342 deletions(-)
delete mode 100644 IRaCIS.Core.Infrastructure/Cache/CacheType.cs
delete mode 100644 IRaCIS.Core.Infrastructure/Cache/ICache.cs
delete mode 100644 IRaCIS.Core.Infrastructure/Cache/MemoryCache.cs
delete mode 100644 IRaCIS.Core.Infrastructure/Cache/RedisCache.cs
diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs
index b36859015..3a6af0f62 100644
--- a/IRaCIS.Core.Application/Service/Management/UserService.cs
+++ b/IRaCIS.Core.Application/Service/Management/UserService.cs
@@ -8,7 +8,6 @@ using Panda.DynamicWebApi.Attributes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Caching.Memory;
-using IRaCIS.Core.Infra.Common.Cache;
using Microsoft.Identity.Client;
using static IRaCIS.Core.Domain.Share.StaticData;
using IRaCIS.Core.Application.ViewModel;
diff --git a/IRaCIS.Core.Domain.Share/IRaCIS.Core.Domain.Share.csproj b/IRaCIS.Core.Domain.Share/IRaCIS.Core.Domain.Share.csproj
index 85a1db3cc..bbcde76bb 100644
--- a/IRaCIS.Core.Domain.Share/IRaCIS.Core.Domain.Share.csproj
+++ b/IRaCIS.Core.Domain.Share/IRaCIS.Core.Domain.Share.csproj
@@ -10,6 +10,10 @@
+
+
+
+
diff --git a/IRaCIS.Core.Infrastructure/Cache/CacheType.cs b/IRaCIS.Core.Infrastructure/Cache/CacheType.cs
deleted file mode 100644
index 5f64f0cc8..000000000
--- a/IRaCIS.Core.Infrastructure/Cache/CacheType.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-
-namespace IRaCIS.Core.Infra.Common.Cache
-{
- ///
- /// 缓存类型
- ///
- public enum CacheType
- {
- ///
- /// 内存缓存
- ///
- Memory,
- ///
- /// Redis缓存
- ///
- Redis
- }
-}
diff --git a/IRaCIS.Core.Infrastructure/Cache/ICache.cs b/IRaCIS.Core.Infrastructure/Cache/ICache.cs
deleted file mode 100644
index defd2dd98..000000000
--- a/IRaCIS.Core.Infrastructure/Cache/ICache.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using System;
-using System.Threading.Tasks;
-
-namespace IRaCIS.Core.Infra.Common.Cache
-{
- ///
- /// 缓存接口
- ///
- public interface ICache
- {
- ///
- /// 用于在 key 存在时删除 key
- ///
- /// 键
- long Del(params string[] key);
-
- ///
- /// 用于在 key 存在时删除 key
- ///
- /// 键
- ///
- Task DelAsync(params string[] key);
-
- ///
- /// 用于在 key 模板存在时删除
- ///
- /// key模板
- ///
- Task DelByPatternAsync(string pattern);
-
- ///
- /// 检查给定 key 是否存在
- ///
- /// 键
- ///
- bool Exists(string key);
-
- ///
- /// 检查给定 key 是否存在
- ///
- /// 键
- ///
- Task ExistsAsync(string key);
-
- ///
- /// 获取指定 key 的值
- ///
- /// 键
- ///
- string Get(string key);
-
- ///
- /// 获取指定 key 的值
- ///
- /// byte[] 或其他类型
- /// 键
- ///
- T Get(string key);
-
- ///
- /// 获取指定 key 的值
- ///
- /// 键
- ///
- Task GetAsync(string key);
-
- ///
- /// 获取指定 key 的值
- ///
- /// byte[] 或其他类型
- /// 键
- ///
- Task GetAsync(string key);
-
- ///
- /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
- ///
- /// 键
- /// 值
- bool Set(string key, object value);
-
- ///
- /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
- ///
- /// 键
- /// 值
- /// 有效期
- bool Set(string key, object value, TimeSpan expire);
-
- ///
- /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
- ///
- /// 键
- /// 值
- ///
- Task SetAsync(string key, object value);
-
- ///
- /// 设置指定 key 的值,所有写入参数object都支持string | byte[] | 数值 | 对象
- ///
- /// 键
- /// 值
- /// 有效期
- ///
- Task SetAsync(string key, object value, TimeSpan expire);
- }
-}
diff --git a/IRaCIS.Core.Infrastructure/Cache/MemoryCache.cs b/IRaCIS.Core.Infrastructure/Cache/MemoryCache.cs
deleted file mode 100644
index 16ffd5760..000000000
--- a/IRaCIS.Core.Infrastructure/Cache/MemoryCache.cs
+++ /dev/null
@@ -1,127 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using Microsoft.Extensions.Caching.Memory;
-
-namespace IRaCIS.Core.Infra.Common.Cache
-{
- ///
- /// 内存缓存
- ///
- public class MemoryCache : ICache
- {
- private readonly IMemoryCache _memoryCache;
- public MemoryCache(IMemoryCache memoryCache)
- {
- _memoryCache = memoryCache;
- }
-
- public long Del(params string[] key)
- {
- foreach(var k in key)
- {
- _memoryCache.Remove(k);
- }
- return key.Length;
- }
-
- public Task DelAsync(params string[] key)
- {
- foreach (var k in key)
- {
- _memoryCache.Remove(k);
- }
-
- return Task.FromResult((long)key.Length);
- }
-
- public async Task DelByPatternAsync(string pattern)
- {
- if (string.IsNullOrEmpty(pattern))
- return default;
-
- pattern = Regex.Replace(pattern, @"\{.*\}", "(.*)");
-
- var keys = GetAllKeys().Where(k => Regex.IsMatch(k, pattern));
-
- if(keys != null && keys.Count() > 0)
- {
- return await DelAsync(keys.ToArray());
- }
-
- return default;
- }
-
- public bool Exists(string key)
- {
- return _memoryCache.TryGetValue(key, out _);
- }
-
- public Task ExistsAsync(string key)
- {
- return Task.FromResult(_memoryCache.TryGetValue(key, out _));
- }
-
- public string Get(string key)
- {
- return _memoryCache.Get(key)?.ToString();
- }
-
- public T Get(string key)
- {
- return _memoryCache.Get(key);
- }
-
- public Task GetAsync(string key)
- {
- return Task.FromResult(Get(key));
- }
-
- public Task GetAsync(string key)
- {
- return Task.FromResult(Get(key));
- }
-
- public bool Set(string key, object value)
- {
- _memoryCache.Set(key, value);
- return true;
- }
-
- public bool Set(string key, object value, TimeSpan expire)
- {
- _memoryCache.Set(key, value, expire);
- return true;
- }
-
- public Task SetAsync(string key, object value)
- {
- Set(key, value);
- return Task.FromResult(true);
- }
-
- public Task SetAsync(string key, object value, TimeSpan expire)
- {
- Set(key, value, expire);
- return Task.FromResult(true);
- }
-
- private List GetAllKeys()
- {
- const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
- var entries = _memoryCache.GetType().GetField("_entries", flags).GetValue(_memoryCache);
- var cacheItems = entries as IDictionary;
- var keys = new List();
- if (cacheItems == null) return keys;
- foreach (DictionaryEntry cacheItem in cacheItems)
- {
- keys.Add(cacheItem.Key.ToString());
- }
- return keys;
- }
- }
-}
diff --git a/IRaCIS.Core.Infrastructure/Cache/RedisCache.cs b/IRaCIS.Core.Infrastructure/Cache/RedisCache.cs
deleted file mode 100644
index 1c540178f..000000000
--- a/IRaCIS.Core.Infrastructure/Cache/RedisCache.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-
-namespace IRaCIS.Core.Infra.Common.Cache
-{
- ///
- /// Redis缓存
- ///
- public class RedisCache : ICache
- {
- public long Del(params string[] key)
- {
- return RedisHelper.Del(key);
- }
-
- public Task DelAsync(params string[] key)
- {
- return RedisHelper.DelAsync(key);
- }
-
- public async Task DelByPatternAsync(string pattern)
- {
- if (string.IsNullOrEmpty(pattern))
- return default;
-
- pattern = Regex.Replace(pattern, @"\{.*\}", "*");
-
- var keys = (await RedisHelper.KeysAsync(pattern));
- if(keys != null && keys.Length > 0)
- {
- return await RedisHelper.DelAsync(keys);
- }
-
- return default;
- }
-
- public bool Exists(string key)
- {
- return RedisHelper.Exists(key);
- }
-
- public Task ExistsAsync(string key)
- {
- return RedisHelper.ExistsAsync(key);
- }
-
- public string Get(string key)
- {
- return RedisHelper.Get(key);
- }
-
- public T Get(string key)
- {
- return RedisHelper.Get(key);
- }
-
- public Task GetAsync(string key)
- {
- return RedisHelper.GetAsync(key);
- }
-
- public Task GetAsync(string key)
- {
- return RedisHelper.GetAsync(key);
- }
-
- public bool Set(string key, object value)
- {
- return RedisHelper.Set(key, value);
- }
-
- public bool Set(string key, object value, TimeSpan expire)
- {
- return RedisHelper.Set(key, value, expire);
- }
-
- public Task SetAsync(string key, object value)
- {
- return RedisHelper.SetAsync(key, value);
- }
-
- public Task SetAsync(string key, object value, TimeSpan expire)
- {
- return RedisHelper.SetAsync(key, value, expire);
- }
- }
-}
diff --git a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj
index 66854efcc..714d8b400 100644
--- a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj
+++ b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj
@@ -10,12 +10,12 @@
-
+