aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn/MemoryCacheUtil.cs
diff options
context:
space:
mode:
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