From edc00ddaab46a2a2d0ba07591a6206159421ef41 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 24 Jul 2019 18:34:28 -0400 Subject: remove cached mod data not requested within 48 hours (#651) --- src/SMAPI.Web/Framework/Caching/Mods/IModCacheRepository.cs | 5 +++++ src/SMAPI.Web/Framework/Caching/Mods/ModCacheRepository.cs | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'src/SMAPI.Web/Framework/Caching/Mods') diff --git a/src/SMAPI.Web/Framework/Caching/Mods/IModCacheRepository.cs b/src/SMAPI.Web/Framework/Caching/Mods/IModCacheRepository.cs index 23929d1d..bcec8b36 100644 --- a/src/SMAPI.Web/Framework/Caching/Mods/IModCacheRepository.cs +++ b/src/SMAPI.Web/Framework/Caching/Mods/IModCacheRepository.cs @@ -1,3 +1,4 @@ +using System; using StardewModdingAPI.Toolkit.Framework.UpdateData; using StardewModdingAPI.Web.Framework.ModRepositories; @@ -22,5 +23,9 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods /// The mod data. /// The stored mod record. void SaveMod(ModRepositoryKey site, string id, ModInfoModel mod, out CachedMod cachedMod); + + /// Delete data for mods which haven't been requested within a given time limit. + /// The minimum age for which to remove mods. + void RemoveStaleMods(TimeSpan age); } } diff --git a/src/SMAPI.Web/Framework/Caching/Mods/ModCacheRepository.cs b/src/SMAPI.Web/Framework/Caching/Mods/ModCacheRepository.cs index d8ad7d21..4258cc85 100644 --- a/src/SMAPI.Web/Framework/Caching/Mods/ModCacheRepository.cs +++ b/src/SMAPI.Web/Framework/Caching/Mods/ModCacheRepository.cs @@ -67,6 +67,14 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods cachedMod = this.SaveMod(new CachedMod(site, id, mod)); } + /// Delete data for mods which haven't been requested within a given time limit. + /// The minimum age for which to remove mods. + public void RemoveStaleMods(TimeSpan age) + { + DateTimeOffset minDate = DateTimeOffset.UtcNow.Subtract(age); + var result = this.Mods.DeleteMany(p => p.LastRequested < minDate); + } + /********* ** Private methods -- cgit