#243 disabling caching by default for most of ganjoor related information

This commit is contained in:
Hamid Reza Mohammadi 2021-11-19 10:04:47 +03:30
parent a5fb6273db
commit 2dc0df2404
3 changed files with 41 additions and 9 deletions

View File

@ -49,7 +49,8 @@ namespace RMuseum.Controllers
return BadRequest(res.ExceptionString);
poets = res.Result;
_memoryCache.Set(cacheKey, poets);
if (AggressiveCacheEnabled)
_memoryCache.Set(cacheKey, poets);
}
return Ok(poets);
@ -76,7 +77,8 @@ namespace RMuseum.Controllers
return BadRequest(res.ExceptionString);
centuries = res.Result;
_memoryCache.Set(cacheKey, centuries);
if (AggressiveCacheEnabled)
_memoryCache.Set(cacheKey, centuries);
}
return Ok(centuries);
@ -125,7 +127,8 @@ namespace RMuseum.Controllers
if (res.Result == null)
return NotFound();
poet = res.Result;
_memoryCache.Set(cacheKey, poet);
if (AggressiveCacheEnabled)
_memoryCache.Set(cacheKey, poet);
}
return Ok(poet);
}
@ -153,7 +156,8 @@ namespace RMuseum.Controllers
if (res.Result == null)
return NotFound();
poet = res.Result;
_memoryCache.Set(cacheKey, poet);
if (AggressiveCacheEnabled)
_memoryCache.Set(cacheKey, poet);
}
return Ok(poet);
}
@ -414,7 +418,10 @@ namespace RMuseum.Controllers
if (res.Result == null)
return NotFound();
cat = res.Result;
_memoryCache.Set(cacheKey, cat);
if(AggressiveCacheEnabled)
{
_memoryCache.Set(cacheKey, cat);
}
}
return Ok(cat);
}
@ -443,7 +450,8 @@ namespace RMuseum.Controllers
if (res.Result == null)
return NotFound();
cat = res.Result;
_memoryCache.Set(cacheKey, cat);
if (AggressiveCacheEnabled)
_memoryCache.Set(cacheKey, cat);
}
@ -2233,6 +2241,24 @@ namespace RMuseum.Controllers
/// </summary>
protected readonly IMemoryCache _memoryCache;
/// <summary>
/// aggressive cache
/// </summary>
private bool AggressiveCacheEnabled
{
get
{
try
{
return bool.Parse(Configuration["AggressiveCacheEnabled"]);
}
catch
{
return false;
}
}
}
/// <summary>
/// Configuration
/// </summary>

View File

@ -1335,6 +1335,11 @@
IMemoryCache
</summary>
</member>
<member name="P:RMuseum.Controllers.GanjoorController.AggressiveCacheEnabled">
<summary>
aggressive cache
</summary>
</member>
<member name="P:RMuseum.Controllers.GanjoorController.Configuration">
<summary>
Configuration

View File

@ -76,7 +76,8 @@ namespace RMuseum.Services.Implementation
StringComparer fa = StringComparer.Create(new CultureInfo("fa-IR"), true);
res.Sort((a, b) => fa.Compare(a.Nickname, b.Nickname));
poets = res.ToArray();
_memoryCache.Set(cacheKey, poets);
if (AggressiveCacheEnabled)
_memoryCache.Set(cacheKey, poets);
}
return new RServiceResult<GanjoorPoetViewModel[]>
@ -102,7 +103,7 @@ namespace RMuseum.Services.Implementation
return new RServiceResult<GanjoorPoetCompleteViewModel>(null);
var cat = await _context.GanjoorCategories.Where(c => c.ParentId == null && c.PoetId == id).AsNoTracking().FirstOrDefaultAsync();
poetCat = (await GetCatById(cat.Id, catPoems)).Result;
if (poetCat != null)
if (poetCat != null && AggressiveCacheEnabled)
{
_memoryCache.Set(cacheKey, poetCat);
}
@ -498,7 +499,7 @@ namespace RMuseum.Services.Implementation
}
break;
}
if ((AggressiveCacheEnabled || page.GanjoorPageType == GanjoorPageType.CatPage) && page.FullUrl != "/hashieha" && page.FullUrl != "/vazn" && page.FullUrl != "/simi" && page.FullUrl != "/audioclip")
if (AggressiveCacheEnabled)
{
_memoryCache.Set(cachKey, page);
}