feat(Web): Verteilter Sql Server-Cache hinzugefügt.
- Bat-Datei erstellt, um Tabelle für Cache zu erstellen. - Sql-Datei zum Erstellen einer Tabelle für den Cache erstellt
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user