public void Reset(ShardId shardId = default) { lock (this) { if (shardId.Count <= 1) { _caches.Clear(); foreach (var type in _supportedTypes) { var cacheType = typeof(SynchronizedDictionary <,>).MakeGenericType(typeof(Snowflake), type); var cache = Activator.CreateInstance(cacheType); _caches.Add(type, cache); } _nestedCaches.Clear(); foreach (var type in _supportedNestedTypes) { var cache = new SynchronizedDictionary <Snowflake, object>(); _nestedCaches.Add(type, cache); } } else { if (_caches.GetValueOrDefault(typeof(CachedGuild)) is ISynchronizedDictionary <Snowflake, CachedGuild> guildsCache) { lock (guildsCache) { foreach (var guildId in guildsCache.Keys.Where(x => ShardId.ForGuildId(x, shardId.Count) == shardId)) { guildsCache.Remove(guildId); if (this.TryGetChannels(guildId, out var channelCache)) { channelCache.Clear(); } if (this.TryGetMembers(guildId, out var memberCache)) { memberCache.Clear(); } if (this.TryGetRoles(guildId, out var roleCache)) { roleCache.Clear(); } if (this.TryGetVoiceStates(guildId, out var voiceStates)) { voiceStates.Clear(); } } } } } } }
/// <inheritdoc/> public void Reset(ShardId shardId = default) { lock (this) { if (shardId.Count <= 1) { _caches.Clear(); foreach (var type in _supportedTypes) { var cacheType = typeof(SynchronizedDictionary <,>).MakeGenericType(typeof(Snowflake), type); var cache = Activator.CreateInstance(cacheType); _caches.Add(type, cache); } _nestedCaches.Clear(); foreach (var type in _supportedNestedTypes) { var cache = new SynchronizedDictionary <Snowflake, object>(); _nestedCaches.Add(type, cache); } } else { if (_caches.GetValueOrDefault(typeof(CachedGuild)) is ISynchronizedDictionary <Snowflake, CachedGuild> guildsCache) { lock (guildsCache) { foreach (var guildId in guildsCache.Keys) { if (ShardId.ForGuildId(guildId, shardId.Count) != shardId) { continue; } guildsCache.Remove(guildId); InternalReset(guildId); } } } } } }
public static ShardId GetShardId(this IGatewayClient client, Snowflake?guildId) => ShardId.ForGuildId(guildId ?? 0, client.Shards.Count);