Skip to content

Commit

Permalink
Cache cleanup is now fire and forget
Browse files Browse the repository at this point in the history
  • Loading branch information
HeDo88TH committed Dec 2, 2024
1 parent 0d35112 commit a4f2d9e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Registry.Web/Services/Managers/ObjectsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ public async Task<EntryDto> AddNew(string orgSlug, string dsSlug, string path, S
_logger.LogInformation("This item is an image, generate thumbnail");

// Run task in background
_ = _cacheManager.Get(MagicStrings.ThumbnailCacheSeed, entry.Hash, ddb, localFilePath, DefaultThumbnailSize);
_ = _cacheManager.Get(MagicStrings.ThumbnailCacheSeed, entry.Hash, ddb, localFilePath,
DefaultThumbnailSize);

_logger.LogInformation("Thumbnail generation task started");

}

return entry.ToDto();
Expand Down Expand Up @@ -389,8 +389,23 @@ public async Task Delete(string orgSlug, string dsSlug, string path)

_logger.LogInformation("Local file deleted, now clearing cache with hash {Hash}", obj.Hash);

_cacheManager.Clear(MagicStrings.ThumbnailCacheSeed, obj.Hash);
_cacheManager.Clear(MagicStrings.TileCacheSeed, obj.Hash);
// Clear cache in a fire-and-forget task
#pragma warning disable CS4014
Task.Run(() =>
#pragma warning restore CS4014
{
try
{
_cacheManager.Clear(MagicStrings.ThumbnailCacheSeed, obj.Hash);
_cacheManager.Clear(MagicStrings.TileCacheSeed, obj.Hash);

_logger.LogInformation("Cache cleared for hash {Hash}", obj.Hash);
}
catch (Exception cacheEx)
{
_logger.LogError(cacheEx, "Error while clearing cache for hash {Hash}", obj.Hash);
}
});

_logger.LogInformation("Cache cleared");
}
Expand Down

0 comments on commit a4f2d9e

Please sign in to comment.