diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs index b4b20460f6..99bf3b4cae 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs @@ -1,4 +1,7 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Caching.Distributed; +using Volo.Abp.Caching; using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Contents; using Volo.CmsKit.GlobalFeatures; @@ -11,11 +14,13 @@ public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppSe { protected IPageRepository PageRepository { get; } protected ContentParser ContentParser { get; } + private readonly IDistributedCache _cache; - public PagePublicAppService(IPageRepository pageRepository, ContentParser contentParser) + public PagePublicAppService(IPageRepository pageRepository, ContentParser contentParser, IDistributedCache cache) { PageRepository = pageRepository; ContentParser = contentParser; + _cache = cache; } public virtual async Task FindBySlugAsync(string slug) @@ -34,14 +39,21 @@ public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppSe public virtual async Task FindDefaultHomePageAsync() { - var page = await PageRepository.FindByIsHomePageAsync(true); - - if (page == null) + var pageDto = await _cache.GetAsync("DefaultHomePage"); + if (pageDto is null) { - return null; + var page = await PageRepository.FindByIsHomePageAsync(true); + if (page is null) + { + return null; + } + + pageDto = ObjectMapper.Map(page); + + await _cache.SetAsync("DefaultHomePage", pageDto, + new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.Now.AddHours(1) }); } - var pageDto = ObjectMapper.Map(page); return pageDto; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs index 6e30c49a9c..6e679e1c82 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs @@ -5,6 +5,7 @@ using Volo.Abp; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Components.LayoutHook; using Volo.Abp.AutoMapper; +using Volo.Abp.Caching; using Volo.Abp.GlobalFeatures; using Volo.Abp.Http.ProxyScripting.Generators.JQuery; using Volo.Abp.Modularity; @@ -76,6 +77,11 @@ public class CmsKitPublicWebModule : AbpModule { options.DisableModule(CmsKitPublicRemoteServiceConsts.ModuleName); }); + + Configure(options => + { + options.KeyPrefix = "CmsKit:"; + }); } public override void PostConfigureServices(ServiceConfigurationContext context)