2021-12-13 20:39:41 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.Caching;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
using RehauSku.Assistant;
|
2021-12-13 20:39:41 +03:00
|
|
|
|
|
2021-12-24 16:22:03 +03:00
|
|
|
|
namespace RehauSku
|
2021-12-13 20:39:41 +03:00
|
|
|
|
{
|
2021-12-24 16:22:03 +03:00
|
|
|
|
static class MemoryCacheUtil
|
2021-12-13 20:39:41 +03:00
|
|
|
|
{
|
|
|
|
|
public static bool IsCached(this string request)
|
|
|
|
|
{
|
2021-12-24 16:22:03 +03:00
|
|
|
|
return AddIn.memoryCache.Contains(request);
|
2021-12-13 20:39:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IProduct GetFromCache(this string request)
|
|
|
|
|
{
|
2021-12-24 16:22:03 +03:00
|
|
|
|
return AddIn.memoryCache[request] as IProduct;
|
2021-12-13 20:39:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<IProduct> RequestAndCache(this string request)
|
|
|
|
|
{
|
|
|
|
|
IProduct product = await SkuAssist.GetProductAsync(request);
|
|
|
|
|
|
|
|
|
|
if (product == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2021-12-24 16:22:03 +03:00
|
|
|
|
AddIn.memoryCache.Add(request, product, DateTime.Now.AddMinutes(10));
|
2021-12-13 20:39:41 +03:00
|
|
|
|
return product;
|
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
|
|
|
|
public static void ClearCache()
|
|
|
|
|
{
|
|
|
|
|
AddIn.memoryCache.Dispose();
|
|
|
|
|
AddIn.memoryCache = new MemoryCache("RehauSku");
|
|
|
|
|
}
|
2021-12-13 20:39:41 +03:00
|
|
|
|
}
|
|
|
|
|
}
|