using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Distributed; namespace EnvelopeGenerator.Web.Controllers.Test { [Route("api/[controller]")] [ApiController] public class TestCacheController : ControllerBase { private readonly IDistributedCache _cache; public TestCacheController(IDistributedCache cache) { _cache = cache; } [HttpPost] public async Task SetCacheAsync(string key, string value) { var options = new DistributedCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromMinutes(5)); await _cache.SetStringAsync(key, value, options); return Ok(); } [HttpGet] public async Task GetCacheAsync(string key) { var value = await _cache.GetStringAsync(key); return value is null ? BadRequest() : Ok(value); } } }