caching for poets
This commit is contained in:
parent
85e046f384
commit
59eeb8c24f
@ -1813,8 +1813,7 @@ namespace RMuseum.Controllers
|
||||
/// <param name="userPermissionChecker"></param>
|
||||
/// <param name="memoryCache"></param>
|
||||
/// <param name="captchaService"></param>
|
||||
/// <param name="notificationService"></param>
|
||||
public ArtifactController(IArtifactService artifactService, IUserPermissionChecker userPermissionChecker, IMemoryCache memoryCache, ICaptchaService captchaService, IRNotificationService notificationService)
|
||||
public ArtifactController(IArtifactService artifactService, IUserPermissionChecker userPermissionChecker, IMemoryCache memoryCache, ICaptchaService captchaService)
|
||||
{
|
||||
_artifactService = artifactService;
|
||||
_userPermissionChecker = userPermissionChecker;
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.Auth.ViewModel;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.GanjoorIntegration.ViewModels;
|
||||
using RMuseum.Services;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using RSecurityBackend.Models.Auth.ViewModels;
|
||||
@ -40,11 +40,19 @@ namespace RMuseum.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public async Task<IActionResult> GetPoets(bool websitePoets = true, bool includeBio = true)
|
||||
{
|
||||
RServiceResult<GanjoorPoetViewModel[]> res =
|
||||
var cacheKey = $"ganjoor/poets/{websitePoets}/{includeBio}";
|
||||
if (!_memoryCache.TryGetValue(cacheKey, out GanjoorPoetViewModel[] poets))
|
||||
{
|
||||
RServiceResult<GanjoorPoetViewModel[]> res =
|
||||
await _ganjoorService.GetPoets(websitePoets, includeBio);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok(res.Result);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
poets = res.Result;
|
||||
_memoryCache.Set(cacheKey, poets);
|
||||
|
||||
}
|
||||
return Ok(poets);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1144,6 +1152,11 @@ namespace RMuseum.Controllers
|
||||
/// </summary>
|
||||
protected readonly IImageFileService _imageFileService;
|
||||
|
||||
/// <summary>
|
||||
/// IMemoryCache
|
||||
/// </summary>
|
||||
protected readonly IMemoryCache _memoryCache;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
@ -1151,12 +1164,14 @@ namespace RMuseum.Controllers
|
||||
/// <param name="appUserService"></param>
|
||||
/// <param name="httpContextAccessor"></param>
|
||||
/// <param name="imageFileService"></param>
|
||||
public GanjoorController(IGanjoorService ganjoorService, IAppUserService appUserService, IHttpContextAccessor httpContextAccessor, IImageFileService imageFileService)
|
||||
/// <param name="memoryCache"></param>
|
||||
public GanjoorController(IGanjoorService ganjoorService, IAppUserService appUserService, IHttpContextAccessor httpContextAccessor, IImageFileService imageFileService, IMemoryCache memoryCache)
|
||||
{
|
||||
_ganjoorService = ganjoorService;
|
||||
_appUserService = appUserService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_imageFileService = imageFileService;
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -572,7 +572,7 @@
|
||||
<param name="linkId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.ArtifactController.#ctor(RMuseum.Services.IArtifactService,RSecurityBackend.Services.IUserPermissionChecker,Microsoft.Extensions.Caching.Memory.IMemoryCache,RSecurityBackend.Services.ICaptchaService,RSecurityBackend.Services.IRNotificationService)">
|
||||
<member name="M:RMuseum.Controllers.ArtifactController.#ctor(RMuseum.Services.IArtifactService,RSecurityBackend.Services.IUserPermissionChecker,Microsoft.Extensions.Caching.Memory.IMemoryCache,RSecurityBackend.Services.ICaptchaService)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
@ -581,7 +581,6 @@
|
||||
<param name="userPermissionChecker"></param>
|
||||
<param name="memoryCache"></param>
|
||||
<param name="captchaService"></param>
|
||||
<param name="notificationService"></param>
|
||||
</member>
|
||||
<member name="F:RMuseum.Controllers.ArtifactController._artifactService">
|
||||
<summary>
|
||||
@ -943,7 +942,12 @@
|
||||
Image Service
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.#ctor(RMuseum.Services.IGanjoorService,RSecurityBackend.Services.IAppUserService,Microsoft.AspNetCore.Http.IHttpContextAccessor,RSecurityBackend.Services.IImageFileService)">
|
||||
<member name="F:RMuseum.Controllers.GanjoorController._memoryCache">
|
||||
<summary>
|
||||
IMemoryCache
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.#ctor(RMuseum.Services.IGanjoorService,RSecurityBackend.Services.IAppUserService,Microsoft.AspNetCore.Http.IHttpContextAccessor,RSecurityBackend.Services.IImageFileService,Microsoft.Extensions.Caching.Memory.IMemoryCache)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
@ -951,6 +955,7 @@
|
||||
<param name="appUserService"></param>
|
||||
<param name="httpContextAccessor"></param>
|
||||
<param name="imageFileService"></param>
|
||||
<param name="memoryCache"></param>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.ImageController.Get(System.Guid,System.String)">
|
||||
<summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user