- Bat-Datei erstellt, um Tabelle für Cache zu erstellen. - Sql-Datei zum Erstellen einer Tabelle für den Cache erstellt
36 lines
976 B
C#
36 lines
976 B
C#
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<IActionResult> 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<IActionResult> GetCacheAsync(string key)
|
|
{
|
|
var value = await _cache.GetStringAsync(key);
|
|
return value is null ? BadRequest() : Ok(value);
|
|
}
|
|
}
|
|
}
|