summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-16 14:30:07 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-16 14:30:07 -0400
commit5e6f1640dcb8e30a44f8ff07572874850b12cc2e (patch)
tree48f259c0d052b6d4e104a951681ae8df7e341e76 /src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs
parenta2cfb71d898aca98d621f1b86dd5611337eea034 (diff)
downloadSMAPI-5e6f1640dcb8e30a44f8ff07572874850b12cc2e.tar.gz
SMAPI-5e6f1640dcb8e30a44f8ff07572874850b12cc2e.tar.bz2
SMAPI-5e6f1640dcb8e30a44f8ff07572874850b12cc2e.zip
simplify single-instance deployment and make MongoDB server optional
Diffstat (limited to 'src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs')
-rw-r--r--src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs b/src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs
new file mode 100644
index 00000000..4621f5e3
--- /dev/null
+++ b/src/SMAPI.Web/Framework/Caching/Wiki/WikiCacheMemoryRepository.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
+
+namespace StardewModdingAPI.Web.Framework.Caching.Wiki
+{
+ /// <summary>Manages cached wiki data in-memory.</summary>
+ internal class WikiCacheMemoryRepository : BaseCacheRepository, IWikiCacheRepository
+ {
+ /*********
+ ** Fields
+ *********/
+ /// <summary>The saved wiki metadata.</summary>
+ private CachedWikiMetadata Metadata;
+
+ /// <summary>The cached wiki data.</summary>
+ private CachedWikiMod[] Mods = new CachedWikiMod[0];
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Get the cached wiki metadata.</summary>
+ /// <param name="metadata">The fetched metadata.</param>
+ public bool TryGetWikiMetadata(out CachedWikiMetadata metadata)
+ {
+ metadata = this.Metadata;
+ return metadata != null;
+ }
+
+ /// <summary>Get the cached wiki mods.</summary>
+ /// <param name="filter">A filter to apply, if any.</param>
+ public IEnumerable<CachedWikiMod> GetWikiMods(Expression<Func<CachedWikiMod, bool>> filter = null)
+ {
+ return filter != null
+ ? this.Mods.Where(filter.Compile())
+ : this.Mods.ToArray();
+ }
+
+ /// <summary>Save data fetched from the wiki compatibility list.</summary>
+ /// <param name="stableVersion">The current stable Stardew Valley version.</param>
+ /// <param name="betaVersion">The current beta Stardew Valley version.</param>
+ /// <param name="mods">The mod data.</param>
+ /// <param name="cachedMetadata">The stored metadata record.</param>
+ /// <param name="cachedMods">The stored mod records.</param>
+ public void SaveWikiData(string stableVersion, string betaVersion, IEnumerable<WikiModEntry> mods, out CachedWikiMetadata cachedMetadata, out CachedWikiMod[] cachedMods)
+ {
+ this.Metadata = cachedMetadata = new CachedWikiMetadata(stableVersion, betaVersion);
+ this.Mods = cachedMods = mods.Select(mod => new CachedWikiMod(mod)).ToArray();
+ }
+ }
+}