using System; using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Toolkit.Framework.Clients.Wiki; namespace StardewModdingAPI.Web.Framework.Caching.Wiki { /// Manages cached wiki data in-memory. internal class WikiCacheMemoryRepository : BaseCacheRepository, IWikiCacheRepository { /********* ** Fields *********/ /// The saved wiki metadata. private Cached Metadata; /// The cached wiki data. private Cached[] Mods = new Cached[0]; /********* ** Public methods *********/ /// Get the cached wiki metadata. /// The fetched metadata. public bool TryGetWikiMetadata(out Cached metadata) { metadata = this.Metadata; return metadata != null; } /// Get the cached wiki mods. /// A filter to apply, if any. public IEnumerable> GetWikiMods(Func filter = null) { foreach (var mod in this.Mods) { if (filter == null || filter(mod.Data)) yield return mod; } } /// Save data fetched from the wiki compatibility list. /// The current stable Stardew Valley version. /// The current beta Stardew Valley version. /// The mod data. public void SaveWikiData(string stableVersion, string betaVersion, IEnumerable mods) { this.Metadata = new Cached(new WikiMetadata(stableVersion, betaVersion)); this.Mods = mods.Select(mod => new Cached(mod)).ToArray(); } } }