diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-26 18:22:32 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-26 18:22:32 +0300 |
commit | 54fc3320e7d64d7903b4d091fe0d5c15df01fd78 (patch) | |
tree | ac8b9aa1e883a85339a594b2797ab319cca73c4e /src/AddIn/MemoryCacheUtil.cs | |
parent | 20cfbfcca3a779c04aecdca5e4b465651e2be42a (diff) |
Move to /src
Diffstat (limited to 'src/AddIn/MemoryCacheUtil.cs')
-rw-r--r-- | src/AddIn/MemoryCacheUtil.cs | 37 |
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 |