From ada351b163d928b5c01787e3ac3ad25ee6fe1ce4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 16 Mar 2018 20:28:16 -0400 Subject: reduce cache time for failed update checks to 5 minutes (#454) --- docs/release-notes.md | 1 + src/SMAPI.Web/Controllers/ModsApiController.cs | 12 ++++++++---- src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs | 7 +++++-- src/SMAPI.Web/appsettings.json | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 393090f2..9d654133 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -21,6 +21,7 @@ * Fixed rare crash with some combinations of manifest fields and internal mod data. * Fixed update checks failing for Nexus Mods due to a change in their API. * Fixed update checks failing for some older mods with non-standard versions. + * Fixed failed update checks being cached for an hour (now cached 5 minutes). * Fixed error when a content pack needs a mod that couldn't be loaded. * Fixed Linux ["magic number is wrong" errors](https://github.com/mono/mono/issues/6752) by changing default terminal order. * Updated compatibility list and added update checks for more mods. diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index c99c87fb..24517263 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -29,8 +29,11 @@ namespace StardewModdingAPI.Web.Controllers /// The cache in which to store mod metadata. private readonly IMemoryCache Cache; - /// The number of minutes update checks should be cached before refetching them. - private readonly int CacheMinutes; + /// The number of minutes successful update checks should be cached before refetching them. + private readonly int SuccessCacheMinutes; + + /// The number of minutes failed update checks should be cached before refetching them. + private readonly int ErrorCacheMinutes; /// A regex which matches SMAPI-style semantic version. private readonly string VersionRegex; @@ -50,7 +53,8 @@ namespace StardewModdingAPI.Web.Controllers ModUpdateCheckConfig config = configProvider.Value; this.Cache = cache; - this.CacheMinutes = config.CacheMinutes; + this.SuccessCacheMinutes = config.SuccessCacheMinutes; + this.ErrorCacheMinutes = config.ErrorCacheMinutes; this.VersionRegex = config.SemanticVersionRegex; this.Repositories = new IModRepository[] @@ -121,7 +125,7 @@ namespace StardewModdingAPI.Web.Controllers } // cache & return - entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.CacheMinutes); + entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(info.Error == null ? this.SuccessCacheMinutes : this.ErrorCacheMinutes); return info; }); } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs index 58c3a100..fc3b7dc2 100644 --- a/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs +++ b/src/SMAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs @@ -6,8 +6,11 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels /********* ** Accessors *********/ - /// The number of minutes update checks should be cached before refetching them. - public int CacheMinutes { get; set; } + /// The number of minutes successful update checks should be cached before refetching them. + public int SuccessCacheMinutes { get; set; } + + /// The number of minutes failed update checks should be cached before refetching them. + public int ErrorCacheMinutes { get; set; } /// A regex which matches SMAPI-style semantic version. /// Derived from SMAPI's SemanticVersion implementation. diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index bfe827fa..03ca31ed 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -40,7 +40,8 @@ }, "ModUpdateCheck": { - "CacheMinutes": 60, + "SuccessCacheMinutes": 60, + "ErrorCacheMinutes": 5, "SemanticVersionRegex": "^(?>(?0|[1-9]\\d*))\\.(?>(?0|[1-9]\\d*))(?>(?:\\.(?0|[1-9]\\d*))?)(?:-(?(?>[a-z0-9]+[\\-\\.]?)+))?$", "ChucklefishKey": "Chucklefish", -- cgit