From 4ea6a4102bb69b72391334c4825bd393eff6ac97 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Jul 2017 15:08:14 -0400 Subject: add support for partial cache invalidation (#335) --- src/StardewModdingAPI/Program.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 50ab4e25..56c56431 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -796,7 +796,7 @@ namespace StardewModdingAPI if (this.DeprecationManager.IsVirtualMethodImplemented(mod.GetType(), typeof(Mod), nameof(Mod.Entry), new[] { typeof(object[]) })) deprecationWarnings.Add(() => this.DeprecationManager.Warn(metadata.DisplayName, $"{nameof(Mod)}.{nameof(Mod.Entry)}(object[]) instead of {nameof(Mod)}.{nameof(Mod.Entry)}({nameof(IModHelper)})", "1.0", DeprecationLevel.PendingRemoval)); #else - if (!this.DeprecationManager.IsVirtualMethodImplemented(mod.GetType(), typeof(Mod), nameof(Mod.Entry), new[] {typeof(IModHelper)})) + if (!this.DeprecationManager.IsVirtualMethodImplemented(mod.GetType(), typeof(Mod), nameof(Mod.Entry), new[] { typeof(IModHelper) })) this.Monitor.Log($"{metadata.DisplayName} doesn't implement Entry() and may not work correctly.", LogLevel.Error); #endif } @@ -812,19 +812,27 @@ namespace StardewModdingAPI { if (metadata.Mod.Helper.Content is ContentHelper helper) { + // TODO: optimise by only reloading assets the new editors/loaders can intercept helper.ObservableAssetEditors.CollectionChanged += (sender, e) => { if (e.NewItems.Count > 0) - this.ContentManager.Reset(); + { + this.Monitor.Log("Detected new asset editor, resetting cache...", LogLevel.Trace); + this.ContentManager.InvalidateCache(p => true); + } }; helper.ObservableAssetLoaders.CollectionChanged += (sender, e) => { if (e.NewItems.Count > 0) - this.ContentManager.Reset(); + { + this.Monitor.Log("Detected new asset loader, resetting cache...", LogLevel.Trace); + this.ContentManager.InvalidateCache(p => true); + } }; } } - this.ContentManager.Reset(); + this.Monitor.Log("Resetting cache to enable interception...", LogLevel.Trace); + this.ContentManager.InvalidateCache(p => true); } /// Reload translations for all mods. -- cgit