caching poet by url
This commit is contained in:
parent
c18a8616e5
commit
bc8f6e3a15
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user