Skip to content

Commit

Permalink
fix(ux): 🐛 clear cache when token changes (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed May 19, 2023
1 parent e96cac8 commit 324cbb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/NullableCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
}
}
}
3 changes: 3 additions & 0 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ internal async ValueTask<bool> 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();
Expand Down

0 comments on commit 324cbb5

Please sign in to comment.