Utilities.ClearCache

This commit is contained in:
Haiping Chen 2023-12-27 09:33:03 -06:00
parent 4c6c035b07
commit b3311a1917
5 changed files with 21 additions and 4 deletions

View file

@ -60,6 +60,8 @@ public partial class AgentService
_db.Add<IBotSharpTable>(userAgentRecord);
});
Utilities.ClearCache();
return agentRecord;
}

View file

@ -1,6 +1,6 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Repositories;
using Microsoft.Extensions.Caching.Memory;
using System.IO;
namespace BotSharp.Core.Agents.Services;
@ -51,5 +51,7 @@ public partial class AgentService
_db.BulkInsertAgents(agents);
_db.BulkInsertUserAgents(userAgents);
Utilities.ClearCache();
}
}

View file

@ -33,6 +33,9 @@ public partial class AgentService
}
_db.UpdateAgent(record, updateField);
Utilities.ClearCache();
await Task.CompletedTask;
}
@ -66,6 +69,8 @@ public partial class AgentService
.SetLlmConfig(foundAgent.LlmConfig);
_db.UpdateAgent(clonedAgent, AgentField.All);
Utilities.ClearCache();
}
await Task.CompletedTask;

View file

@ -1,3 +1,5 @@
using Microsoft.Extensions.Caching.Memory;
namespace BotSharp.Core.Infrastructures;
public static class Utilities
@ -20,4 +22,13 @@ public static class Utilities
var splits = str.Split(sep);
return (splits[0], splits[1]);
}
public static void ClearCache()
{
// Clear whole cache.
if (new MemoryCacheAttribute(0).Cache is MemoryCache memcache)
{
memcache.Compact(100);
}
}
}

View file

@ -1,6 +1,3 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Functions.Models;
namespace BotSharp.OpenAPI.Controllers;
[Authorize]