/// <summary>
        /// Add the specified token to the cache.
        /// </summary>
        /// <param name="token">The token to add to the cache.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
        /// <returns>
        /// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
        /// </returns>
        public async Task AddAsync([NotNull] TToken token, CancellationToken cancellationToken)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            _cache.Remove(new
            {
                Method  = nameof(FindAsync),
                Subject = await _store.GetSubjectAsync(token, cancellationToken),
                Client  = await _store.GetApplicationIdAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method  = nameof(FindAsync),
                Subject = await _store.GetSubjectAsync(token, cancellationToken),
                Client  = await _store.GetApplicationIdAsync(token, cancellationToken),
                Status  = await _store.GetStatusAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method  = nameof(FindAsync),
                Subject = await _store.GetSubjectAsync(token, cancellationToken),
                Client  = await _store.GetApplicationIdAsync(token, cancellationToken),
                Status  = await _store.GetStatusAsync(token, cancellationToken),
                Type    = await _store.GetTypeAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method     = nameof(FindByApplicationIdAsync),
                Identifier = await _store.GetApplicationIdAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method     = nameof(FindByAuthorizationIdAsync),
                Identifier = await _store.GetAuthorizationIdAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method     = nameof(FindByIdAsync),
                Identifier = await _store.GetIdAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method     = nameof(FindByReferenceIdAsync),
                Identifier = await _store.GetReferenceIdAsync(token, cancellationToken)
            });

            _cache.Remove(new
            {
                Method  = nameof(FindBySubjectAsync),
                Subject = await _store.GetSubjectAsync(token, cancellationToken)
            });

            var signal = await CreateExpirationSignalAsync(token, cancellationToken);

            if (signal == null)
            {
                throw new InvalidOperationException("An error occurred while creating an expiration signal.");
            }

            using (var entry = _cache.CreateEntry(new
            {
                Method = nameof(FindByIdAsync),
                Identifier = await _store.GetIdAsync(token, cancellationToken)
            }))
            {
                entry.AddExpirationToken(signal)
                .SetSize(1L)
                .SetValue(token);
            }

            using (var entry = _cache.CreateEntry(new
            {
                Method = nameof(FindByReferenceIdAsync),
                Identifier = await _store.GetReferenceIdAsync(token, cancellationToken)
            }))
            {
                entry.AddExpirationToken(signal)
                .SetSize(1L)
                .SetValue(token);
            }
        }
Beispiel #2
0
    /// <inheritdoc/>
    public async ValueTask AddAsync(TToken token, CancellationToken cancellationToken)
    {
        if (token is null)
        {
            throw new ArgumentNullException(nameof(token));
        }

        _cache.Remove(new
        {
            Method  = nameof(FindAsync),
            Subject = await _store.GetSubjectAsync(token, cancellationToken),
            Client  = await _store.GetApplicationIdAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method  = nameof(FindAsync),
            Subject = await _store.GetSubjectAsync(token, cancellationToken),
            Client  = await _store.GetApplicationIdAsync(token, cancellationToken),
            Status  = await _store.GetStatusAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method  = nameof(FindAsync),
            Subject = await _store.GetSubjectAsync(token, cancellationToken),
            Client  = await _store.GetApplicationIdAsync(token, cancellationToken),
            Status  = await _store.GetStatusAsync(token, cancellationToken),
            Type    = await _store.GetTypeAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method     = nameof(FindByApplicationIdAsync),
            Identifier = await _store.GetApplicationIdAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method     = nameof(FindByAuthorizationIdAsync),
            Identifier = await _store.GetAuthorizationIdAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method     = nameof(FindByIdAsync),
            Identifier = await _store.GetIdAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method     = nameof(FindByReferenceIdAsync),
            Identifier = await _store.GetReferenceIdAsync(token, cancellationToken)
        });

        _cache.Remove(new
        {
            Method  = nameof(FindBySubjectAsync),
            Subject = await _store.GetSubjectAsync(token, cancellationToken)
        });

        await CreateEntryAsync(new
        {
            Method     = nameof(FindByIdAsync),
            Identifier = await _store.GetIdAsync(token, cancellationToken)
        }, token, cancellationToken);

        await CreateEntryAsync(new
        {
            Method     = nameof(FindByReferenceIdAsync),
            Identifier = await _store.GetReferenceIdAsync(token, cancellationToken)
        }, token, cancellationToken);
    }