public async Task <Response <InvestmentsResponse> > Handle(InvestmentsRequest request, CancellationToken cancellationToken)
        {
            var responseCache = await _cache.GetAsync(CacheKeys.Portfolio, cancellationToken);

            if (responseCache is null)
            {
                _tracer.ActiveSpan.SetTag("cache", false);
                var investmentResponse = await _portfolio.GetAsync();

                _ = _cache.SetAsync(CacheKeys.Portfolio, JsonSerializer.SerializeToUtf8Bytes(investmentResponse), DateTime.Now.UntilMidnight(), cancellationToken);
                return(new Response <InvestmentsResponse>(investmentResponse));
            }
            else
            {
                _tracer.ActiveSpan.SetTag("cache", true);
                var investmentResponse = JsonSerializer.Deserialize <InvestmentsResponse>(new ReadOnlySpan <byte>(responseCache));
                return(new Response <InvestmentsResponse>(investmentResponse));
            }
        }
Exemplo n.º 2
0
        public async Task UpdateAsync()
        {
            var investmentResponse = await _portfolio.GetAsync();

            _ = _cache.SetAsync(CacheKeys.Portfolio, JsonSerializer.SerializeToUtf8Bytes(investmentResponse), DateTime.Now.UntilMidnight());
        }