Add configurable cache duration
This commit is contained in:
@@ -14,5 +14,11 @@
|
|||||||
/// The User-Agent string used in HTTP requests.
|
/// The User-Agent string used in HTTP requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserAgent { get; set; }
|
public string UserAgent { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The duration in minutes to cache the indexer requests.
|
||||||
|
/// </summary>
|
||||||
|
public int IndexerRequestsCacheDurationInMinutes { get; set; } = 12;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,11 @@ internal class Program
|
|||||||
|
|
||||||
builder.Services.AddSerilog();
|
builder.Services.AddSerilog();
|
||||||
|
|
||||||
|
|
||||||
|
// Log all configuration values
|
||||||
|
LogConfigurationValues(configuration);
|
||||||
|
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddHttpClient("HttpClient").ConfigurePrimaryHttpMessageHandler(() =>
|
builder.Services.AddHttpClient("HttpClient").ConfigurePrimaryHttpMessageHandler(() =>
|
||||||
{
|
{
|
||||||
@@ -118,4 +123,15 @@ internal class Program
|
|||||||
//.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently
|
//.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void LogConfigurationValues(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
Log.Information("Logging all configuration values at startup:");
|
||||||
|
|
||||||
|
foreach (var kvp in configuration.AsEnumerable())
|
||||||
|
{
|
||||||
|
Log.Information("{Key}: {Value}", kvp.Key, kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
|
|
||||||
if (responseMessage.IsSuccessStatusCode)
|
if (responseMessage.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_cache.Set(targetUri, responseMessage, TimeSpan.FromMinutes(12));
|
_cache.Set(targetUri, responseMessage, TimeSpan.FromMinutes(_options.IndexerRequestsCacheDurationInMinutes));
|
||||||
}
|
}
|
||||||
|
|
||||||
return responseMessage;
|
return responseMessage;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public static class ServicesExtensions
|
|||||||
Console.WriteLine(($"Property {failure.PropertyName } failed validation. Error was: {failure.ErrorMessage}"));
|
Console.WriteLine(($"Property {failure.PropertyName } failed validation. Error was: {failure.ErrorMessage}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception("Please fix cour environment variables and then Start UmlautAdaptarr again");
|
throw new Exception("Please fix your environment variables and then Start UmlautAdaptarr again");
|
||||||
}
|
}
|
||||||
|
|
||||||
var instanceState = (bool)(typeof(TOptions).GetProperty("Enabled")?.GetValue(option, null) ?? false);
|
var instanceState = (bool)(typeof(TOptions).GetProperty("Enabled")?.GetValue(option, null) ?? false);
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ namespace UmlautAdaptarr.Validator;
|
|||||||
|
|
||||||
public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOptions>
|
public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOptions>
|
||||||
{
|
{
|
||||||
private readonly static HttpClient httpClient = new() {
|
private readonly static HttpClient httpClient = new()
|
||||||
|
{
|
||||||
Timeout = TimeSpan.FromSeconds(3)
|
Timeout = TimeSpan.FromSeconds(3)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,5 +69,4 @@ public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOp
|
|||||||
|
|
||||||
return reachable;
|
return reachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,6 @@ services:
|
|||||||
- LIDARR__ENABLED=false
|
- LIDARR__ENABLED=false
|
||||||
- LIDARR__HOST=http://localhost:8686
|
- LIDARR__HOST=http://localhost:8686
|
||||||
- LIDARR__APIKEY=APIKEY
|
- LIDARR__APIKEY=APIKEY
|
||||||
#- IpLeakTest__Enabled=false # uncomment and set to true to enable IP leak test
|
|
||||||
### example for multiple instances of same type
|
### example for multiple instances of same type
|
||||||
#- SONARR__0__NAME=NAME 1 (optional)
|
#- SONARR__0__NAME=NAME 1 (optional)
|
||||||
#- SONARR__0__ENABLED=false
|
#- SONARR__0__ENABLED=false
|
||||||
@@ -33,3 +32,8 @@ services:
|
|||||||
#- SONARR__1__ENABLED=false
|
#- SONARR__1__ENABLED=false
|
||||||
#- SONARR__1__HOST=http://localhost:8989
|
#- SONARR__1__HOST=http://localhost:8989
|
||||||
#- SONARR__1__APIKEY=APIKEY
|
#- SONARR__1__APIKEY=APIKEY
|
||||||
|
|
||||||
|
### Advanced options (with default values))
|
||||||
|
#- IpLeakTest__Enabled=false
|
||||||
|
#- SETTINGS__IndexerRequestsCacheDurationInMinutes=12
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user