aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn/MemoryCacheUtil.cs
diff options
context:
space:
mode:
authorSerghei Cebotari <51533848+schebotar@users.noreply.github.com>2021-12-26 19:37:46 +0300
committerGitHub <noreply@github.com>2021-12-26 19:37:46 +0300
commitfc870d19555cc77b0e08912b4dab21d496b2321f (patch)
treeac8b9aa1e883a85339a594b2797ab319cca73c4e /src/AddIn/MemoryCacheUtil.cs
parent0525ec1b42d5857b740dd0dae7f6d9baeb7088d1 (diff)
parent54fc3320e7d64d7903b4d091fe0d5c15df01fd78 (diff)
Merge pull request #9 from schebotar/dev
Move to /src
Diffstat (limited to 'src/AddIn/MemoryCacheUtil.cs')
-rw-r--r--src/AddIn/MemoryCacheUtil.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/AddIn/MemoryCacheUtil.cs b/src/AddIn/MemoryCacheUtil.cs
new file mode 100644
index 0000000..1d42e14
--- /dev/null
+++ b/src/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