From 37e56206d4b098d54145b1f92d451e254a36c7c1 Mon Sep 17 00:00:00 2001 From: Efra Date: Thu, 26 Jun 2025 20:42:36 -0600 Subject: [PATCH] fix: added temporary method to clear collections cache --- .../Service/MongoSampleService.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Core.Blueprint.DAL.Mongo/Service/MongoSampleService.cs b/Core.Blueprint.DAL.Mongo/Service/MongoSampleService.cs index 27089cb..9a0164f 100644 --- a/Core.Blueprint.DAL.Mongo/Service/MongoSampleService.cs +++ b/Core.Blueprint.DAL.Mongo/Service/MongoSampleService.cs @@ -29,6 +29,8 @@ namespace Core.Blueprint.DAL.Mongo.Service await this.repository.InsertOneAsync(sampleCollection); + await ResetCollectionCache(); + return sampleCollection; } @@ -65,15 +67,33 @@ namespace Core.Blueprint.DAL.Mongo.Service public async ValueTask UpdateSample(string _id, SampleCollection entity, CancellationToken cancellationToken) { await this.repository.ReplaceOneAsync(entity); + + await ResetCollectionCache(); return entity; } + public async ValueTask DeleteSample(string _id, CancellationToken cancellationToken) { var entity = await this.repository.DeleteOneAsync(doc => doc._Id == _id); + + await ResetCollectionCache(); return entity; + } + + /// + /// Temporary method to "reset" collections cache + /// + /// + private async Task ResetCollectionCache() + { + //TODO: remoge this mehtod when necessary. + var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllSamples"); + + await cacheProvider.SetAsync(cacheKey, Enumerable.Empty(), null); } + } }