summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-23 19:25:34 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-23 19:25:34 -0400
commitd7add894419543667e60569bfeb439e8e797a4d1 (patch)
tree0b0b53e6ac306f1549951abe806bded7f9236bd1 /src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs
parent9aba50451b617e1af8215358afda22c8105477f2 (diff)
downloadSMAPI-d7add894419543667e60569bfeb439e8e797a4d1.tar.gz
SMAPI-d7add894419543667e60569bfeb439e8e797a4d1.tar.bz2
SMAPI-d7add894419543667e60569bfeb439e8e797a4d1.zip
drop MongoDB code
MongoDB support unnecessarily complicated the code and there's no need to run distributed servers in the foreseeable future. This keeps the abstract storage interface so we can wrap a distributed cache in the future.
Diffstat (limited to 'src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs')
-rw-r--r--src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs b/src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs
index 9c5a217e..62461116 100644
--- a/src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs
+++ b/src/SMAPI.Web/Framework/Caching/Mods/ModCacheMemoryRepository.cs
@@ -13,7 +13,7 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods
** Fields
*********/
/// <summary>The cached mod data indexed by <c>{site key}:{ID}</c>.</summary>
- private readonly IDictionary<string, CachedMod> Mods = new Dictionary<string, CachedMod>(StringComparer.InvariantCultureIgnoreCase);
+ private readonly IDictionary<string, Cached<ModInfoModel>> Mods = new Dictionary<string, Cached<ModInfoModel>>(StringComparer.InvariantCultureIgnoreCase);
/*********
@@ -24,19 +24,20 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods
/// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
/// <param name="mod">The fetched mod.</param>
/// <param name="markRequested">Whether to update the mod's 'last requested' date.</param>
- public bool TryGetMod(ModRepositoryKey site, string id, out CachedMod mod, bool markRequested = true)
+ public bool TryGetMod(ModRepositoryKey site, string id, out Cached<ModInfoModel> mod, bool markRequested = true)
{
// get mod
- if (!this.Mods.TryGetValue(this.GetKey(site, id), out mod))
+ if (!this.Mods.TryGetValue(this.GetKey(site, id), out var cachedMod))
+ {
+ mod = null;
return false;
+ }
// bump 'last requested'
if (markRequested)
- {
- mod.LastRequested = DateTimeOffset.UtcNow;
- mod = this.SaveMod(mod);
- }
+ cachedMod.LastRequested = DateTimeOffset.UtcNow;
+ mod = cachedMod;
return true;
}
@@ -44,11 +45,10 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods
/// <param name="site">The mod site on which the mod is found.</param>
/// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
/// <param name="mod">The mod data.</param>
- /// <param name="cachedMod">The stored mod record.</param>
- public void SaveMod(ModRepositoryKey site, string id, ModInfoModel mod, out CachedMod cachedMod)
+ public void SaveMod(ModRepositoryKey site, string id, ModInfoModel mod)
{
string key = this.GetKey(site, id);
- cachedMod = this.SaveMod(new CachedMod(site, id, mod));
+ this.Mods[key] = new Cached<ModInfoModel>(mod);
}
/// <summary>Delete data for mods which haven't been requested within a given time limit.</summary>
@@ -66,14 +66,6 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods
this.Mods.Remove(key);
}
- /// <summary>Save data fetched for a mod.</summary>
- /// <param name="mod">The mod data.</param>
- public CachedMod SaveMod(CachedMod mod)
- {
- string key = this.GetKey(mod.Site, mod.ID);
- return this.Mods[key] = mod;
- }
-
/*********
** Private methods
@@ -81,7 +73,7 @@ namespace StardewModdingAPI.Web.Framework.Caching.Mods
/// <summary>Get a cache key.</summary>
/// <param name="site">The mod site.</param>
/// <param name="id">The mod ID.</param>
- public string GetKey(ModRepositoryKey site, string id)
+ private string GetKey(ModRepositoryKey site, string id)
{
return $"{site}:{id.Trim()}".ToLower();
}