Replace CacheCache with SharpCache

This commit is contained in:
nick.yi 2025-01-22 13:47:32 +08:00
parent 84e4b4bf0d
commit 6d21ba2c0a
5 changed files with 9 additions and 8 deletions

View file

@ -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";
}

View file

@ -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<PagedItems<Agent>> 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<Agent> GetAgent(string id)
{

View file

@ -7,7 +7,7 @@ public partial class AgentService
{
public static ConcurrentDictionary<string, Dictionary<string, string>> AgentParameterTypes = new();
[MemoryCache(10 * 60, perInstanceCache: true)]
[SharpCache(10, perInstanceCache: true)]
public async Task<Agent> LoadAgent(string id, bool loadUtility = true)
{
if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())

View file

@ -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<string> profiles)
{

View file

@ -377,7 +377,7 @@ public class UserService : IUserService
return await _cacheService.GetAsync<DateTime>(GetUserTokenExpiresCacheKey(_user.Id));
}
[MemoryCache(10 * 60, perInstanceCache: true)]
[SharpCache(10, perInstanceCache: true)]
public async Task<User> GetMyProfile()
{
var db = _services.GetRequiredService<IBotSharpRepository>();
@ -398,7 +398,7 @@ public class UserService : IUserService
return user;
}
[MemoryCache(10 * 60, perInstanceCache: true)]
[SharpCache(10, perInstanceCache: true)]
public async Task<User> GetUser(string id)
{
var db = _services.GetRequiredService<IBotSharpRepository>();