aboutsummaryrefslogtreecommitdiff
path: root/Source/Assistant/MemoryCacheExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Assistant/MemoryCacheExtensions.cs')
-rw-r--r--Source/Assistant/MemoryCacheExtensions.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/Assistant/MemoryCacheExtensions.cs b/Source/Assistant/MemoryCacheExtensions.cs
new file mode 100644
index 0000000..7eb1408
--- /dev/null
+++ b/Source/Assistant/MemoryCacheExtensions.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Runtime.Caching;
+using System.Threading.Tasks;
+
+namespace RehauSku.Assistant
+{
+ static class MemoryCacheExtensions
+ {
+ public static bool IsCached(this string request)
+ {
+ return MemoryCache.Default.Contains(request);
+ }
+
+ public static IProduct GetFromCache(this string request)
+ {
+ return MemoryCache.Default[request] as IProduct;
+ }
+
+ public static async Task<IProduct> RequestAndCache(this string request)
+ {
+ IProduct product = await SkuAssist.GetProductAsync(request);
+
+ if (product == null)
+ return null;
+
+ MemoryCache.Default.Add(request, product, DateTime.Now.AddMinutes(10));
+ return product;
+ }
+ }
+} \ No newline at end of file