2022-03-29 05:03:01 +00:00
|
|
|
|
using RegexBot.Data;
|
2019-02-16 00:49:54 +00:00
|
|
|
|
|
2022-03-29 05:03:01 +00:00
|
|
|
|
namespace RegexBot.Services.EntityCache;
|
|
|
|
|
/// <summary>
|
2022-07-21 01:55:08 +00:00
|
|
|
|
/// Provides and maintains a database-backed cache of entities.
|
2022-03-29 05:03:01 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
class EntityCacheService : Service {
|
|
|
|
|
private readonly UserCachingSubservice _uc;
|
2022-05-12 03:26:28 +00:00
|
|
|
|
private readonly MessageCachingSubservice _mc;
|
2019-02-16 00:49:54 +00:00
|
|
|
|
|
2022-03-29 05:03:01 +00:00
|
|
|
|
internal EntityCacheService(RegexbotClient bot) : base(bot) {
|
|
|
|
|
// Currently we only have UserCache. May add Channel and Server caches later.
|
|
|
|
|
_uc = new UserCachingSubservice(bot);
|
2022-05-12 03:26:28 +00:00
|
|
|
|
_mc = new MessageCachingSubservice(bot, Log);
|
2018-12-05 20:47:25 +00:00
|
|
|
|
}
|
2022-03-29 05:03:01 +00:00
|
|
|
|
|
|
|
|
|
// Hooked
|
2022-05-12 03:26:28 +00:00
|
|
|
|
internal CachedUser? QueryUserCache(string search)
|
|
|
|
|
=> _uc.DoUserQuery(search);
|
|
|
|
|
|
|
|
|
|
// Hooked
|
|
|
|
|
internal CachedGuildUser? QueryGuildUserCache(ulong guildId, string search)
|
|
|
|
|
=> _uc.DoGuildUserQuery(guildId, search);
|
2022-03-29 05:03:01 +00:00
|
|
|
|
|
|
|
|
|
// Hooked
|
2022-07-08 19:03:15 +00:00
|
|
|
|
internal event RegexbotClient.EcMessageUpdateHandler? OnCachePreUpdate {
|
2022-05-12 03:26:28 +00:00
|
|
|
|
add { lock (_mc) _mc.OnCachePreUpdate += value; }
|
|
|
|
|
remove { lock (_mc) _mc.OnCachePreUpdate -= value; }
|
|
|
|
|
}
|
2018-12-05 20:47:25 +00:00
|
|
|
|
}
|