Esempio n. 1
0
        public async Task <IActionResult> GetProvidedService(int id)
        {
            if (_memorycache.TryGetValue(string.Format(GET_PROVIDEDSERVICES_CACHE, id), out GetProvidedServiceViewModel providedService))
            {
                return(Ok(providedService));
            }

            var query  = new GetProvidedServiceQuery(id);
            var result = await _mediator.Send(query);

            if (result == null)
            {
                return(NotFound());
            }

            var memoryCacheOptions = new MemoryCacheEntryOptions
            {
                //Daqui a 1h, irei invalidar a cache
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3600),

                //Tempo decorrido sem requisições => Passa 20 minutos seguidos sem nenhuma requisição
                SlidingExpiration = TimeSpan.FromSeconds(1200)
            };

            _memorycache.Set(string.Format(GET_PROVIDEDSERVICES_CACHE, id), result, memoryCacheOptions);

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetById(int id)
        {
            var query = new GetProvidedServiceQuery(id);

            var result = await _mediator.Send(query);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }