limit in-memory caching duration times

This commit is contained in:
13xforever 2020-08-01 16:23:50 +05:00
parent 2ee0d9eebc
commit e71e9cc8ce
5 changed files with 9 additions and 7 deletions

View File

@ -25,6 +25,7 @@ namespace PsnClient
private readonly MediaTypeFormatterCollection underscoreFormatters;
private readonly MediaTypeFormatterCollection xmlFormatters;
private static readonly MemoryCache ResponseCache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromHours(1) });
private static readonly TimeSpan ResponseCacheDuration = TimeSpan.FromHours(1);
private static readonly Regex ContainerIdLink = new Regex(@"(?<id>STORE-(\w|\d)+-(\w|\d)+)");
private static readonly string[] KnownStoreLocales =
{
@ -251,7 +252,7 @@ namespace PsnClient
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
patchInfo = await response.Content.ReadAsAsync<TitlePatch>(xmlFormatters, cancellationToken).ConfigureAwait(false);
ResponseCache.Set(productId, patchInfo);
ResponseCache.Set(productId, patchInfo, ResponseCacheDuration);
return patchInfo ?? new TitlePatch { Tag = new TitlePatchTag { Packages = new TitlePatchPackage[0], }, };
}
catch (Exception e)
@ -279,7 +280,7 @@ namespace PsnClient
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
meta = await response.Content.ReadAsAsync<TitleMeta>(xmlFormatters, cancellationToken).ConfigureAwait(false);
ResponseCache.Set(id, meta);
ResponseCache.Set(id, meta, ResponseCacheDuration);
return meta;
}
catch (Exception e)

View File

@ -199,7 +199,7 @@ namespace CompatBot.Database.Providers
Config.Log.Trace("Getting dominant color for " + url);
result = ColorGetter.Analyze(memStream.ToArray(), defaultColor);
ColorCache.Set(url, result);
ColorCache.Set(url, result, TimeSpan.FromHours(1));
return result;
}
catch (Exception e)

View File

@ -16,7 +16,7 @@ namespace CompatBot.EventHandlers
internal static class EmpathySimulationHandler
{
private static readonly TCache MessageQueue = new TCache();
private static readonly TimeSpan ThrottleDuration = TimeSpan.FromDays(1);
private static readonly TimeSpan ThrottleDuration = TimeSpan.FromHours(1);
private static readonly MemoryCache Throttling = new MemoryCache(new MemoryCacheOptions {ExpirationScanFrequency = TimeSpan.FromMinutes(30)});
public static async Task OnMessageCreated(MessageCreateEventArgs args)

View File

@ -87,7 +87,7 @@ namespace CompatBot.Utils.Extensions
result = await azureDevOpsClient.GetArtifactsInfoAsync(commit, latestBuild, cancellationToken).ConfigureAwait(false);
if (result.Status == BuildStatus.Completed && (result.Result == BuildResult.Succeeded || result.Result == BuildResult.PartiallySucceeded))
BuildInfoCache.Set(commit, result, TimeSpan.FromDays(1));
BuildInfoCache.Set(commit, result, TimeSpan.FromHours(1));
return result;
}
@ -121,7 +121,7 @@ namespace CompatBot.Utils.Extensions
result = await azureDevOpsClient.GetArtifactsInfoAsync(commit, latestBuild, cancellationToken).ConfigureAwait(false);
if (result.Status == BuildStatus.Completed && (result.Result == BuildResult.Succeeded || result.Result == BuildResult.PartiallySucceeded))
BuildInfoCache.Set(commit, result, TimeSpan.FromDays(1));
BuildInfoCache.Set(commit, result, TimeSpan.FromHours(1));
return result;
}

View File

@ -19,6 +19,7 @@ namespace CompatBot.Utils
?? Encoding.ASCII;
private static readonly Encoding Utf8 = new UTF8Encoding(false);
private static readonly MemoryCache FuzzyPairCache = new MemoryCache(new MemoryCacheOptions {ExpirationScanFrequency = TimeSpan.FromMinutes(10)});
private static readonly TimeSpan CacheTime = TimeSpan.FromMinutes(30);
private const char StrikeThroughChar = '\u0336'; // 0x0335 = short dash, 0x0336 = long dash, 0x0337 = short slash, 0x0338 = long slash
public const char InvisibleSpacer = '\u206a';
public const char Nbsp = '\u00a0';
@ -359,7 +360,7 @@ namespace CompatBot.Utils
StrB = strB,
Coefficient = strA.ToCanonicalForm().GetScoreWithAcronym(strB.ToCanonicalForm()),
};
FuzzyPairCache.Set(cacheKey, match);
FuzzyPairCache.Set(cacheKey, match, CacheTime);
return match.Coefficient;
}