From 0b13882f7997c57248db935948ed25aa72b30251 Mon Sep 17 00:00:00 2001 From: Tatarincev Date: Fri, 21 Apr 2017 10:38:00 +0200 Subject: [PATCH] Allow to load cache configuration from web.config --- VirtoCommerce.Platform.Web/Startup.cs | 23 ++++++++++++++++------- VirtoCommerce.Platform.Web/Web.config | 26 +++++++++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/VirtoCommerce.Platform.Web/Startup.cs b/VirtoCommerce.Platform.Web/Startup.cs index 65917cff0b9..3f155f4a68e 100644 --- a/VirtoCommerce.Platform.Web/Startup.cs +++ b/VirtoCommerce.Platform.Web/Startup.cs @@ -11,6 +11,7 @@ using System.Web.Optimization; using System.Web.Routing; using CacheManager.Core; +using CacheManager.Core.Configuration; using Common.Logging; using Hangfire; using Microsoft.ApplicationInsights.Extensibility; @@ -326,14 +327,22 @@ private static void InitializePlatform(IAppBuilder app, IUnityContainer containe var moduleCatalog = container.Resolve(); #region Caching - var cacheManager = CacheFactory.Build("platformCache", settings => + ICacheManager cacheManager = null; + //Try to load cache configuration from web.config first + if (ConfigurationManager.GetSection(CacheManagerSection.DefaultSectionName) != null) { - //Should be aware to using Web cache cache handle because it not worked in native threads. (Hangfire jobs) - settings - .WithUpdateMode(CacheUpdateMode.Up) - .WithSystemRuntimeCacheHandle("memCacheHandle") - .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromDays(1)); - }); + cacheManager = CacheFactory.FromConfiguration("platformCache"); + } + else + { + cacheManager = CacheFactory.Build("platformCache", settings => + { + //Should be aware to using Web cache cache handle because it not worked in native threads. (Hangfire jobs) + settings.WithUpdateMode(CacheUpdateMode.Up) + .WithSystemRuntimeCacheHandle("memCacheHandle") + .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromDays(1)); + }); + } container.RegisterInstance(cacheManager); #endregion diff --git a/VirtoCommerce.Platform.Web/Web.config b/VirtoCommerce.Platform.Web/Web.config index 8b1a31af79c..af773268702 100644 --- a/VirtoCommerce.Platform.Web/Web.config +++ b/VirtoCommerce.Platform.Web/Web.config @@ -1,6 +1,7 @@  +
@@ -58,6 +59,23 @@ + + + + + + + + + + + + + + + + + @@ -109,13 +127,7 @@ - - - - - - - +