diff options
author | Serghei Cebotari <51533848+schebotar@users.noreply.github.com> | 2021-12-24 17:43:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-24 17:43:04 +0300 |
commit | 0525ec1b42d5857b740dd0dae7f6d9baeb7088d1 (patch) | |
tree | 5d9c814fd023395d894ce36a9040cf7f7330198c /Source/AddIn/MemoryCacheUtil.cs | |
parent | 8e5db1238ad3ed97f51d9f0a9c7de83c00a12983 (diff) | |
parent | 20cfbfcca3a779c04aecdca5e4b465651e2be42a (diff) |
Merge pull request #8 from schebotar/dev
Dev
Diffstat (limited to 'Source/AddIn/MemoryCacheUtil.cs')
-rw-r--r-- | Source/AddIn/MemoryCacheUtil.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Source/AddIn/MemoryCacheUtil.cs b/Source/AddIn/MemoryCacheUtil.cs new file mode 100644 index 0000000..1d42e14 --- /dev/null +++ b/Source/AddIn/MemoryCacheUtil.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.Caching; +using System.Threading.Tasks; +using RehauSku.Assistant; + +namespace RehauSku +{ + static class MemoryCacheUtil + { + public static bool IsCached(this string request) + { + return AddIn.memoryCache.Contains(request); + } + + public static IProduct GetFromCache(this string request) + { + return AddIn.memoryCache[request] as IProduct; + } + + public static async Task<IProduct> RequestAndCache(this string request) + { + IProduct product = await SkuAssist.GetProductAsync(request); + + if (product == null) + return null; + + AddIn.memoryCache.Add(request, product, DateTime.Now.AddMinutes(10)); + return product; + } + + public static void ClearCache() + { + AddIn.memoryCache.Dispose(); + AddIn.memoryCache = new MemoryCache("RehauSku"); + } + } +}
\ No newline at end of file |