caching poet by url

This commit is contained in:
Hamid Reza Mohammadi 2021-05-07 12:55:34 +04:30
parent c18a8616e5
commit bc8f6e3a15

View File

@ -96,13 +96,19 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetPoetByUrl(string url)
{
RServiceResult<GanjoorPoetCompleteViewModel> res =
await _ganjoorService.GetPoetByUrl(url);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
if (res.Result == null)
return NotFound();
return Ok(res.Result);
var cacheKey = $"poet/byurl/{url}";
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetCompleteViewModel poet))
{
RServiceResult<GanjoorPoetCompleteViewModel> res =
await _ganjoorService.GetPoetByUrl(url);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
if (res.Result == null)
return NotFound();
poet = res.Result;
_memoryCache.Set(cacheKey, poet);
}
return Ok(poet);
}
/// <summary>