summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModHelpers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-10-30 00:02:20 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-10-30 00:02:20 -0400
commit08c30eeffd8cc62d00db33d91e3a9a6ab1d376a3 (patch)
tree13f8cd0027f426990028a035cbe0d5db6646636c /src/SMAPI/Framework/ModHelpers
parent6b5c03da4dd29592c41f06d2d3172ba832be9123 (diff)
downloadSMAPI-08c30eeffd8cc62d00db33d91e3a9a6ab1d376a3.tar.gz
SMAPI-08c30eeffd8cc62d00db33d91e3a9a6ab1d376a3.tar.bz2
SMAPI-08c30eeffd8cc62d00db33d91e3a9a6ab1d376a3.zip
let mods invalidate assets matching a predicate (#363)
Diffstat (limited to 'src/SMAPI/Framework/ModHelpers')
-rw-r--r--src/SMAPI/Framework/ModHelpers/ContentHelper.cs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs
index ae812e71..711897eb 100644
--- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs
@@ -163,9 +163,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <returns>Returns whether the given asset key was cached.</returns>
public bool InvalidateCache(string key)
{
- this.Monitor.Log($"Requested cache invalidation for '{key}'.", LogLevel.Trace);
string actualKey = this.GetActualAssetKey(key, ContentSource.GameContent);
- return this.ContentManager.InvalidateCache((otherKey, type) => otherKey.Equals(actualKey, StringComparison.InvariantCultureIgnoreCase));
+ this.Monitor.Log($"Requested cache invalidation for '{actualKey}'.", LogLevel.Trace);
+ return this.ContentManager.InvalidateCache(asset => asset.AssetNameEquals(actualKey));
}
/// <summary>Remove all assets of the given type from the cache so they're reloaded on the next request. <b>This can be a very expensive operation and should only be used in very specific cases.</b> This will reload core game assets if needed, but references to the former assets will still show the previous content.</summary>
@@ -177,6 +177,15 @@ namespace StardewModdingAPI.Framework.ModHelpers
return this.ContentManager.InvalidateCache((key, type) => typeof(T).IsAssignableFrom(type));
}
+ /// <summary>Remove matching assets from the content cache so they're reloaded on the next request. This will reload core game assets if needed, but references to the former asset will still show the previous content.</summary>
+ /// <param name="predicate">A predicate matching the assets to invalidate.</param>
+ /// <returns>Returns whether any cache entries were invalidated.</returns>
+ public bool InvalidateCache(Func<IAssetInfo, bool> predicate)
+ {
+ this.Monitor.Log("Requested cache invalidation for all assets matching a predicate.", LogLevel.Trace);
+ return this.ContentManager.InvalidateCache(predicate);
+ }
+
/*********
** Private methods
*********/