From 356117993a0956b1d1db9de481a1f6986685e603 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 17 Dec 2021 12:19:59 +0330 Subject: [PATCH] #262 prevent caching image information based on configuration to allow images to be served correctly during webp conversion process --- RMuseum/RMuseum.xml | 5 +++++ .../Services/Implementation/PictureFileService.cs | 14 ++++++++++++-- RMuseum/appsettings.json | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index d5bee6c8..b73e04a7 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -12102,6 +12102,11 @@ طول تصویر بندانگشتی + + + image info cache + + Image Storage Path diff --git a/RMuseum/Services/Implementation/PictureFileService.cs b/RMuseum/Services/Implementation/PictureFileService.cs index 0d4c7862..d4162c57 100644 --- a/RMuseum/Services/Implementation/PictureFileService.cs +++ b/RMuseum/Services/Implementation/PictureFileService.cs @@ -151,12 +151,15 @@ namespace RMuseum.Services.Implementation public async Task> GetImage(Guid id) { var cachKey = $"PictureFileService::GetImage::{id}"; - if (!_memoryCache.TryGetValue(cachKey, out RPictureFile pictureFile)) + if (!ImageInfoCacheEnabled || !_memoryCache.TryGetValue(cachKey, out RPictureFile pictureFile)) { pictureFile = await _context.PictureFiles.AsNoTracking() .Where(p => p.Id == id) .SingleOrDefaultAsync(); - _memoryCache.Set(cachKey, pictureFile); + if(ImageInfoCacheEnabled) + { + _memoryCache.Set(cachKey, pictureFile); + } } return new RServiceResult( @@ -284,6 +287,11 @@ namespace RMuseum.Services.Implementation /// protected int ThumbnailImageMaxHeight { get { return int.Parse($"{Configuration.GetSection("PictureFileService")["ThumbnailMaxHeight"]}"); } } + /// + /// image info cache + /// + private bool ImageInfoCacheEnabled { get { return bool.Parse($"{Configuration.GetSection("PictureFileService")["ImageInfoCacheEnabled"]}"); } } + /// /// Image Storage Path @@ -514,6 +522,8 @@ namespace RMuseum.Services.Implementation } } + + /// /// Database Contetxt /// diff --git a/RMuseum/appsettings.json b/RMuseum/appsettings.json index 4fe813ca..2736f233 100644 --- a/RMuseum/appsettings.json +++ b/RMuseum/appsettings.json @@ -10,7 +10,8 @@ "NormalImageMaxWidth": "800", "NormalImageMaxHeight": "1350", "ThumbnailImageWidth": "300", - "ThumbnailMaxHeight": "500" + "ThumbnailMaxHeight": "500", + "ImageInfoCacheEnabled": "False" }, "Logging": { "LogLevel": {