From 135fa2a84fc5d51286869f5abf15b1b266ab7076 Mon Sep 17 00:00:00 2001 From: fISHIE <83373559+WhoIsFishie@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:20:43 +0500 Subject: [PATCH] removed caching --- Submission.Api/Controllers/SignController.cs | 46 +++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Submission.Api/Controllers/SignController.cs b/Submission.Api/Controllers/SignController.cs index 16e311d..134f75b 100644 --- a/Submission.Api/Controllers/SignController.cs +++ b/Submission.Api/Controllers/SignController.cs @@ -50,10 +50,13 @@ namespace Submission.Api.Controllers if (validation.Success) { - var cacheKey = $"petition_{petition_id}"; + // var cacheKey = $"petition_{petition_id}"; var pet = await _detailRepository.FindByIdAsync(petition_id); +// var SlugcacheKey = $"petition_slug_{pet.Slug}"; + + if (pet == null) return NotFound(); @@ -89,7 +92,8 @@ namespace Submission.Api.Controllers var Countupdate = Builders.Update.Inc("SignatureCount", 1); await _detailRepository.UpdateOneAsync(count_update_filter, Countupdate); - _cache.Remove(cacheKey); + // _cache.Remove(cacheKey); + //_cache.Remove(SlugcacheKey); return Ok("your signature has been submitted"); } @@ -108,13 +112,13 @@ namespace Submission.Api.Controllers [HttpGet("petition/{petition_id}", Name = "GetPetition")] public async Task GetDisHoe([FromRoute] Guid petition_id) { - var cacheKey = $"petition_{petition_id}"; + //var cacheKey = $"petition_{petition_id}"; - // Try to get from cache - if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto)) - { - return Ok(cachedDto); - } + //// Try to get from cache + //if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto)) + //{ + // return Ok(cachedDto); + //} // Not in cache, fetch from database var pet = await _detailRepository.FindByIdAsync(petition_id); @@ -144,10 +148,10 @@ namespace Submission.Api.Controllers }; // Store in cache with 5 minute expiration - var cacheOptions = new MemoryCacheEntryOptions() - .SetAbsoluteExpiration(TimeSpan.FromHours(1)); + // var cacheOptions = new MemoryCacheEntryOptions() + // .SetAbsoluteExpiration(TimeSpan.FromHours(1)); - _cache.Set(cacheKey, dto, cacheOptions); + // _cache.Set(cacheKey, dto, cacheOptions); return Ok(dto); } @@ -155,13 +159,13 @@ namespace Submission.Api.Controllers [HttpGet("petition/by-slug/{slug}", Name = "GetPetitionBySlug")] public async Task GetPetitionBySlug([FromRoute] string slug) { - var cacheKey = $"petition_slug_{slug}"; + //var cacheKey = $"petition_slug_{slug}"; - // Try to get from cache - if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto)) - { - return Ok(cachedDto); - } + //// Try to get from cache + //if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto)) + //{ + // return Ok(cachedDto); + //} // Not in cache, fetch from database by slug var pet = await _detailRepository.FindOneAsync(x => x.Slug == slug); @@ -190,11 +194,11 @@ namespace Submission.Api.Controllers SignatureCount = pet.SignatureCount }; - // Store in cache with 1 hour expiration - var cacheOptions = new MemoryCacheEntryOptions() - .SetAbsoluteExpiration(TimeSpan.FromHours(1)); + //// Store in cache with 1 hour expiration + //var cacheOptions = new MemoryCacheEntryOptions() + // .SetAbsoluteExpiration(TimeSpan.FromHours(1)); - _cache.Set(cacheKey, dto, cacheOptions); + //_cache.Set(cacheKey, dto, cacheOptions); return Ok(dto); }