Skip to content

Commit b3311a1

Browse files
committed
Utilities.ClearCache
1 parent 4c6c035 commit b3311a1

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.CreateAgent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public async Task<Agent> CreateAgent(Agent agent)
6060
_db.Add<IBotSharpTable>(userAgentRecord);
6161
});
6262

63+
Utilities.ClearCache();
64+
6365
return agentRecord;
6466
}
6567

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using BotSharp.Abstraction.Agents.Models;
2-
using BotSharp.Abstraction.Conversations.Models;
32
using BotSharp.Abstraction.Repositories;
3+
using Microsoft.Extensions.Caching.Memory;
44
using System.IO;
55

66
namespace BotSharp.Core.Agents.Services;
@@ -51,5 +51,7 @@ public async Task RefreshAgents()
5151

5252
_db.BulkInsertAgents(agents);
5353
_db.BulkInsertUserAgents(userAgents);
54+
55+
Utilities.ClearCache();
5456
}
5557
}

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public async Task UpdateAgent(Agent agent, AgentField updateField)
3333
}
3434

3535
_db.UpdateAgent(record, updateField);
36+
37+
Utilities.ClearCache();
38+
3639
await Task.CompletedTask;
3740
}
3841

@@ -66,6 +69,8 @@ public async Task UpdateAgentFromFile(string id)
6669
.SetLlmConfig(foundAgent.LlmConfig);
6770

6871
_db.UpdateAgent(clonedAgent, AgentField.All);
72+
73+
Utilities.ClearCache();
6974
}
7075

7176
await Task.CompletedTask;

src/Infrastructure/BotSharp.Core/Infrastructures/Utilities.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Microsoft.Extensions.Caching.Memory;
2+
13
namespace BotSharp.Core.Infrastructures;
24

35
public static class Utilities
@@ -20,4 +22,13 @@ public static (string, string) SplitAsTuple(this string str, string sep)
2022
var splits = str.Split(sep);
2123
return (splits[0], splits[1]);
2224
}
25+
26+
public static void ClearCache()
27+
{
28+
// Clear whole cache.
29+
if (new MemoryCacheAttribute(0).Cache is MemoryCache memcache)
30+
{
31+
memcache.Compact(100);
32+
}
33+
}
2334
}

src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using BotSharp.Abstraction.Agents.Models;
2-
using BotSharp.Abstraction.Functions.Models;
3-
41
namespace BotSharp.OpenAPI.Controllers;
52

63
[Authorize]

0 commit comments

Comments
 (0)