From 324cbb528ef6dd311def801d49b8ad0d1afaa94a Mon Sep 17 00:00:00 2001 From: James Date: Fri, 19 May 2023 14:43:11 +1200 Subject: [PATCH] fix(ux): :bug: clear cache when token changes (#15) --- src/NullableCache.cs | 8 +++++++- src/TogglTrack.cs | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/NullableCache.cs b/src/NullableCache.cs index 496e2c8..f3ccb53 100644 --- a/src/NullableCache.cs +++ b/src/NullableCache.cs @@ -6,7 +6,7 @@ namespace Flow.Launcher.Plugin.TogglTrack internal class NullableCache { private readonly static object NullObject = new object(); - private readonly MemoryCache _cache = MemoryCache.Default; + private MemoryCache _cache = new MemoryCache("TogglTrack"); internal bool Contains(string key) { @@ -35,5 +35,11 @@ internal object Remove(string key) { return this._cache.Remove(key); } + + internal void Clear() + { + this._cache.Dispose(); + this._cache = new MemoryCache("TogglTrack"); + } } } \ No newline at end of file diff --git a/src/TogglTrack.cs b/src/TogglTrack.cs index f2ace10..36d6aab 100644 --- a/src/TogglTrack.cs +++ b/src/TogglTrack.cs @@ -200,6 +200,9 @@ internal async ValueTask VerifyApiToken() return this._lastToken.IsValid; } + // Clear the cache if the token has changed (#15) + this._cache.Clear(); + if (string.IsNullOrWhiteSpace(this._settings.ApiToken)) { this._semaphores.Token.Release();