|
|
|
@ -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<PageDto> _cache; |
|
|
|
|
|
|
|
public PagePublicAppService(IPageRepository pageRepository, ContentParser contentParser) |
|
|
|
public PagePublicAppService(IPageRepository pageRepository, ContentParser contentParser, IDistributedCache<PageDto> cache) |
|
|
|
{ |
|
|
|
PageRepository = pageRepository; |
|
|
|
ContentParser = contentParser; |
|
|
|
_cache = cache; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<PageDto> FindBySlugAsync(string slug) |
|
|
|
@ -34,14 +39,21 @@ public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppSe |
|
|
|
|
|
|
|
public virtual async Task<PageDto> 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, PageDto>(page); |
|
|
|
|
|
|
|
await _cache.SetAsync("DefaultHomePage", pageDto, |
|
|
|
new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.Now.AddHours(1) }); |
|
|
|
} |
|
|
|
|
|
|
|
var pageDto = ObjectMapper.Map<Page, PageDto>(page); |
|
|
|
return pageDto; |
|
|
|
} |
|
|
|
} |
|
|
|
|