Пример #1
0
        private void CacheGuildPreview(object key, IGuildPreview preview)
        {
            CacheInstance(key, preview);

            foreach (var emoji in preview.Emojis)
            {
                if (emoji.ID is null)
                {
                    continue;
                }

                var emojiKey = KeyHelpers.CreateEmojiCacheKey(preview.ID, emoji.ID.Value);
                Cache(emojiKey, emoji);
            }
        }
Пример #2
0
        /// <summary>
        /// Caches a value. Certain instance types may have specializations which cache more than one value from the
        /// instance.
        /// </summary>
        /// <param name="key">The cache key.</param>
        /// <param name="instance">The instance.</param>
        /// <typeparam name="TInstance">The instance type.</typeparam>
        public void Cache <TInstance>(object key, TInstance instance)
            where TInstance : class
        {
            Action cacheAction = instance switch
            {
                IWebhook webhook => () => CacheWebhook(key, webhook),
                ITemplate template => () => CacheTemplate(key, template),
                IIntegration integration => () => CacheIntegration(key, integration),
                IBan ban => () => CacheBan(key, ban),
                IGuildMember member => () => CacheGuildMember(key, member),
                IGuildPreview preview => () => CacheGuildPreview(key, preview),
                IGuild guild => () => CacheGuild(key, guild),
                IEmoji emoji => () => CacheEmoji(key, emoji),
                IInvite invite => () => CacheInvite(key, invite),
                IMessage message => () => CacheMessage(key, message),
                IChannel channel => () => CacheChannel(key, channel),
                _ => () => CacheInstance(key, instance)
            };

            cacheAction();
        }