-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Runtime.Caching; | ||
|
||
namespace Flow.Launcher.Plugin.TogglTrack | ||
{ | ||
internal class NullableCache | ||
{ | ||
private readonly static object NullObject = new object(); | ||
private readonly MemoryCache _cache = MemoryCache.Default; | ||
|
||
internal bool Contains(string key) | ||
{ | ||
return this._cache.Contains(key); | ||
} | ||
|
||
internal object? Get(string key) | ||
{ | ||
var retrieved = this._cache.Get(key); | ||
|
||
return (retrieved == NullableCache.NullObject) | ||
? null | ||
: retrieved; | ||
} | ||
|
||
internal void Set(string key, object? value, DateTimeOffset absoluteExpiration) | ||
{ | ||
var set = (value is null) | ||
? NullableCache.NullObject | ||
: value; | ||
|
||
this._cache.Set(key, set, absoluteExpiration); | ||
} | ||
|
||
internal object Remove(string key) | ||
{ | ||
return this._cache.Remove(key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters