removed caching

This commit is contained in:
fISHIE
2026-01-28 16:20:43 +05:00
parent 9001b3cc66
commit 135fa2a84f

View File

@@ -50,10 +50,13 @@ namespace Submission.Api.Controllers
if (validation.Success) if (validation.Success)
{ {
var cacheKey = $"petition_{petition_id}"; // var cacheKey = $"petition_{petition_id}";
var pet = await _detailRepository.FindByIdAsync(petition_id); var pet = await _detailRepository.FindByIdAsync(petition_id);
// var SlugcacheKey = $"petition_slug_{pet.Slug}";
if (pet == null) if (pet == null)
return NotFound(); return NotFound();
@@ -89,7 +92,8 @@ namespace Submission.Api.Controllers
var Countupdate = Builders<PetitionDetail>.Update.Inc("SignatureCount", 1); var Countupdate = Builders<PetitionDetail>.Update.Inc("SignatureCount", 1);
await _detailRepository.UpdateOneAsync(count_update_filter, Countupdate); await _detailRepository.UpdateOneAsync(count_update_filter, Countupdate);
_cache.Remove(cacheKey); // _cache.Remove(cacheKey);
//_cache.Remove(SlugcacheKey);
return Ok("your signature has been submitted"); return Ok("your signature has been submitted");
} }
@@ -108,13 +112,13 @@ namespace Submission.Api.Controllers
[HttpGet("petition/{petition_id}", Name = "GetPetition")] [HttpGet("petition/{petition_id}", Name = "GetPetition")]
public async Task<IActionResult> GetDisHoe([FromRoute] Guid petition_id) public async Task<IActionResult> GetDisHoe([FromRoute] Guid petition_id)
{ {
var cacheKey = $"petition_{petition_id}"; //var cacheKey = $"petition_{petition_id}";
// Try to get from cache //// Try to get from cache
if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto)) //if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto))
{ //{
return Ok(cachedDto); // return Ok(cachedDto);
} //}
// Not in cache, fetch from database // Not in cache, fetch from database
var pet = await _detailRepository.FindByIdAsync(petition_id); var pet = await _detailRepository.FindByIdAsync(petition_id);
@@ -144,10 +148,10 @@ namespace Submission.Api.Controllers
}; };
// Store in cache with 5 minute expiration // Store in cache with 5 minute expiration
var cacheOptions = new MemoryCacheEntryOptions() // var cacheOptions = new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromHours(1)); // .SetAbsoluteExpiration(TimeSpan.FromHours(1));
_cache.Set(cacheKey, dto, cacheOptions); // _cache.Set(cacheKey, dto, cacheOptions);
return Ok(dto); return Ok(dto);
} }
@@ -155,13 +159,13 @@ namespace Submission.Api.Controllers
[HttpGet("petition/by-slug/{slug}", Name = "GetPetitionBySlug")] [HttpGet("petition/by-slug/{slug}", Name = "GetPetitionBySlug")]
public async Task<IActionResult> GetPetitionBySlug([FromRoute] string slug) public async Task<IActionResult> GetPetitionBySlug([FromRoute] string slug)
{ {
var cacheKey = $"petition_slug_{slug}"; //var cacheKey = $"petition_slug_{slug}";
// Try to get from cache //// Try to get from cache
if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto)) //if (_cache.TryGetValue(cacheKey, out PetitionDetailsDto cachedDto))
{ //{
return Ok(cachedDto); // return Ok(cachedDto);
} //}
// Not in cache, fetch from database by slug // Not in cache, fetch from database by slug
var pet = await _detailRepository.FindOneAsync(x => x.Slug == slug); var pet = await _detailRepository.FindOneAsync(x => x.Slug == slug);
@@ -190,11 +194,11 @@ namespace Submission.Api.Controllers
SignatureCount = pet.SignatureCount SignatureCount = pet.SignatureCount
}; };
// Store in cache with 1 hour expiration //// Store in cache with 1 hour expiration
var cacheOptions = new MemoryCacheEntryOptions() //var cacheOptions = new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromHours(1)); // .SetAbsoluteExpiration(TimeSpan.FromHours(1));
_cache.Set(cacheKey, dto, cacheOptions); //_cache.Set(cacheKey, dto, cacheOptions);
return Ok(dto); return Ok(dto);
} }