Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Allow to set cache time
KrzysztofPajak5273eb7c9160
diff --git a/src/Core/Grand.Infrastructure/Caching/ICacheBase.cs b/src/Core/Grand.Infrastructure/Caching/ICacheBase.csindex 170849ff1..dac297b89 100644--- a/src/Core/Grand.Infrastructure/Caching/ICacheBase.cs+++ b/src/Core/Grand.Infrastructure/Caching/ICacheBase.cs@@ -9,7 +9,9 @@ namespace Grand.Infrastructure.Cachingpublic interface ICacheBase: IDisposable{Task<T> GetAsync<T>(string key, Func<Task<T>> acquire);+ Task<T> GetAsync<T>(string key, Func<Task<T>> acquire, int cacheTime);T Get<T>(string key, Func<T> acquire);+ T Get<T>(string key, Func<T> acquire, int cacheTime);Task SetAsync(string key, object data, int cacheTime);Task RemoveAsync(string key, bool publisher = true);Task RemoveByPrefix(string prefix, bool publisher = true);diff --git a/src/Core/Grand.Infrastructure/Caching/MemoryCacheBase.cs b/src/Core/Grand.Infrastructure/Caching/MemoryCacheBase.csindex 76680e09a..8289588b7 100644--- a/src/Core/Grand.Infrastructure/Caching/MemoryCacheBase.cs+++ b/src/Core/Grand.Infrastructure/Caching/MemoryCacheBase.cs@@ -38,19 +38,29 @@ namespace Grand.Infrastructure.Caching#region Methodspublic virtual async Task<T> GetAsync<T>(string key, Func<Task<T>> acquire)+ {+ return await GetAsync(key, acquire, CommonHelper.CacheTimeMinutes);+ }++ public virtual async Task<T> GetAsync<T>(string key, Func<Task<T>> acquire, int cacheTime){return await _cache.GetOrCreateAsync(key, entry =>{- entry.SetOptions(GetMemoryCacheEntryOptions(CommonHelper.CacheTimeMinutes));+ entry.SetOptions(GetMemoryCacheEntryOptions(cacheTime));return acquire();});}public T Get<T>(string key, Func<T> acquire)+ {+ return Get<T>(key, acquire, CommonHelper.CacheTimeMinutes);+ }++ public T Get<T>(string key, Func<T> acquire, int cacheTime){return _cache.GetOrCreate(key, entry =>{- entry.SetOptions(GetMemoryCacheEntryOptions(CommonHelper.CacheTimeMinutes));+ entry.SetOptions(GetMemoryCacheEntryOptions(cacheTime));return acquire();});}