From 6d21ba2c0a21686b4d98daef4e47532259d08696 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 22 Jan 2025 13:47:32 +0800 Subject: [PATCH] Replace CacheCache with SharpCache --- .../Infrastructures/SharpCacheSettings.cs | 2 +- .../BotSharp.Core/Agents/Services/AgentService.GetAgents.cs | 4 ++-- .../BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs | 2 +- src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs | 5 +++-- .../BotSharp.Core/Users/Services/UserService.cs | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Infrastructures/SharpCacheSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Infrastructures/SharpCacheSettings.cs index 7413d021..7f42f1ca 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Infrastructures/SharpCacheSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Infrastructures/SharpCacheSettings.cs @@ -2,7 +2,7 @@ namespace BotSharp.Abstraction.Infrastructures; public class SharpCacheSettings { - public bool Enabled { get; set; } = false; + public bool Enabled { get; set; } = true; public CacheType CacheType { get; set; } = Enums.CacheType.MemoryCache; public string Prefix { get; set; } = "cache"; } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs index 04b5c22d..95018a2d 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs @@ -5,7 +5,7 @@ namespace BotSharp.Core.Agents.Services; public partial class AgentService { #if !DEBUG - [MemoryCache(10 * 60, perInstanceCache: true)] + [SharpCache(10, perInstanceCache: true)] #endif public async Task> GetAgents(AgentFilter filter) { @@ -27,7 +27,7 @@ public partial class AgentService } #if !DEBUG - [MemoryCache(10 * 60, perInstanceCache: true)] + [SharpCache(10, perInstanceCache: true)] #endif public async Task GetAgent(string id) { diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index 9e6ad8ee..15ba26a1 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -7,7 +7,7 @@ public partial class AgentService { public static ConcurrentDictionary> AgentParameterTypes = new(); - [MemoryCache(10 * 60, perInstanceCache: true)] + [SharpCache(10, perInstanceCache: true)] public async Task LoadAgent(string id, bool loadUtility = true) { if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString()) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index ef32f018..075307b5 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Routing.Settings; +using BotSharp.Core.Infrastructures; namespace BotSharp.Core.Routing; @@ -74,7 +75,7 @@ public partial class RoutingService : IRoutingService } #if !DEBUG - [MemoryCache(10 * 60)] + [SharpCache(10)] #endif protected RoutingRule[] GetRoutingRecords() { @@ -99,7 +100,7 @@ public partial class RoutingService : IRoutingService } #if !DEBUG - [MemoryCache(10 * 60)] + [SharpCache(10)] #endif public RoutableAgent[] GetRoutableAgents(List profiles) { diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index afb897e7..73053063 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -377,7 +377,7 @@ public class UserService : IUserService return await _cacheService.GetAsync(GetUserTokenExpiresCacheKey(_user.Id)); } - [MemoryCache(10 * 60, perInstanceCache: true)] + [SharpCache(10, perInstanceCache: true)] public async Task GetMyProfile() { var db = _services.GetRequiredService(); @@ -398,7 +398,7 @@ public class UserService : IUserService return user; } - [MemoryCache(10 * 60, perInstanceCache: true)] + [SharpCache(10, perInstanceCache: true)] public async Task GetUser(string id) { var db = _services.GetRequiredService();