reduce cache time for mod compatibility list

This commit is contained in:
Jesse Plamondon-Willard 2018-12-29 15:53:11 -05:00
parent 2990784433
commit 5db5ca1c88
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
5 changed files with 25 additions and 5 deletions

View File

@ -11,6 +11,9 @@
* `Specialised.LoadStageChanged`.
* You can now use `helper.Data.Read/WriteSaveData` as soon as the save is loaded (instead of once the world is initialised).
* For the web UI:
* Reduced mod compatibility list's cache time.
## 2.9.3
* For players:
* Fixed errors hovering items in some cases with SMAPI 2.9.2.

View File

@ -22,7 +22,7 @@ namespace StardewModdingAPI.Web.Controllers
private readonly IMemoryCache Cache;
/// <summary>The number of minutes successful update checks should be cached before refetching them.</summary>
private readonly int SuccessCacheMinutes;
private readonly int CacheMinutes;
/*********
@ -31,12 +31,12 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>Construct an instance.</summary>
/// <param name="cache">The cache in which to store mod metadata.</param>
/// <param name="configProvider">The config settings for mod update checks.</param>
public ModsController(IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider)
public ModsController(IMemoryCache cache, IOptions<ModCompatibilityListConfig> configProvider)
{
ModUpdateCheckConfig config = configProvider.Value;
ModCompatibilityListConfig config = configProvider.Value;
this.Cache = cache;
this.SuccessCacheMinutes = config.SuccessCacheMinutes;
this.CacheMinutes = config.CacheMinutes;
}
/// <summary>Display information for all mods.</summary>
@ -66,7 +66,7 @@ namespace StardewModdingAPI.Web.Controllers
.OrderBy(p => Regex.Replace(p.Name.ToLower(), "[^a-z0-9]", "")) // ignore case, spaces, and special characters when sorting
);
entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.SuccessCacheMinutes);
entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.CacheMinutes);
return model;
});
}

View File

@ -0,0 +1,12 @@
namespace StardewModdingAPI.Web.Framework.ConfigModels
{
/// <summary>The config settings for mod compatibility list.</summary>
internal class ModCompatibilityListConfig
{
/*********
** Accessors
*********/
/// <summary>The number of minutes data from the wiki should be cached before refetching it.</summary>
public int CacheMinutes { get; set; }
}
}

View File

@ -50,6 +50,7 @@ namespace StardewModdingAPI.Web
{
// init configuration
services
.Configure<ModCompatibilityListConfig>(this.Configuration.GetSection("ModCompatibilityList"))
.Configure<ModUpdateCheckConfig>(this.Configuration.GetSection("ModUpdateCheck"))
.Configure<SiteConfig>(this.Configuration.GetSection("Site"))
.Configure<RouteOptions>(options => options.ConstraintMap.Add("semanticVersion", typeof(VersionConstraint)))

View File

@ -47,6 +47,10 @@
"PastebinDevKey": null // see top note
},
"ModCompatibilityList": {
"WikiCacheMinutes": 10
},
"ModUpdateCheck": {
"SuccessCacheMinutes": 60,
"ErrorCacheMinutes": 5,