コード例 #1
0
        /// <inheritdoc />
        public override async Task <Result <IReadOnlyList <IBan> > > GetGuildBansAsync
        (
            Snowflake guildID,
            CancellationToken ct = default
        )
        {
            var collectionKey = KeyHelpers.CreateGuildBansCacheKey(guildID);

            if (_cacheService.TryGetValue <IReadOnlyList <IBan> >(collectionKey, out var cachedInstance))
            {
                return(Result <IReadOnlyList <IBan> > .FromSuccess(cachedInstance));
            }

            var getResult = await base.GetGuildBansAsync(guildID, ct);

            if (!getResult.IsSuccess)
            {
                return(getResult);
            }

            var bans = getResult.Entity;

            _cacheService.Cache(collectionKey, bans);

            foreach (var ban in bans)
            {
                var key = KeyHelpers.CreateGuildBanCacheKey(guildID, ban.User.ID);
                _cacheService.Cache(key, ban);
            }

            return(getResult);
        }