diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-23 15:08:14 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-23 15:08:14 -0400 |
commit | 4ea6a4102bb69b72391334c4825bd393eff6ac97 (patch) | |
tree | 2cc36b050268c2d51158e2c8521faf192ed88f84 /src/StardewModdingAPI/Program.cs | |
parent | 65e820c657e112617399737e83746bf48eb42635 (diff) | |
download | SMAPI-4ea6a4102bb69b72391334c4825bd393eff6ac97.tar.gz SMAPI-4ea6a4102bb69b72391334c4825bd393eff6ac97.tar.bz2 SMAPI-4ea6a4102bb69b72391334c4825bd393eff6ac97.zip |
add support for partial cache invalidation (#335)
Diffstat (limited to 'src/StardewModdingAPI/Program.cs')
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 16 |
1 files changed, 12 insertions, 4 deletions
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); } /// <summary>Reload translations for all mods.</summary> |