Add caching and content-type
This commit is contained in:
parent
9a231c28af
commit
b20157450b
|
@ -6,6 +6,7 @@ using System.Xml;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Oqtane.Enums;
|
using Oqtane.Enums;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
|
@ -28,8 +29,9 @@ namespace Oqtane.Pages
|
||||||
private readonly IUserPermissions _userPermissions;
|
private readonly IUserPermissions _userPermissions;
|
||||||
private readonly ILogManager _logger;
|
private readonly ILogManager _logger;
|
||||||
private readonly Alias _alias;
|
private readonly Alias _alias;
|
||||||
|
private readonly IMemoryCache _memoryCache;
|
||||||
|
|
||||||
public SitemapModel(IServiceProvider serviceProvider, IPageRepository pages, IPageModuleRepository pageModules, IModuleDefinitionRepository moduleDefinitions, ISettingRepository settings, IUserPermissions userPermissions, IUrlMappingRepository urlMappings, ISyncManager syncManager, ILogManager logger, ITenantManager tenantManager)
|
public SitemapModel(IServiceProvider serviceProvider, IPageRepository pages, IPageModuleRepository pageModules, IModuleDefinitionRepository moduleDefinitions, ISettingRepository settings, IUserPermissions userPermissions, IUrlMappingRepository urlMappings, ISyncManager syncManager, ILogManager logger, ITenantManager tenantManager, IMemoryCache memoryCache)
|
||||||
{
|
{
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_pages = pages;
|
_pages = pages;
|
||||||
|
@ -39,9 +41,12 @@ namespace Oqtane.Pages
|
||||||
_userPermissions = userPermissions;
|
_userPermissions = userPermissions;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_alias = tenantManager.GetAlias();
|
_alias = tenantManager.GetAlias();
|
||||||
|
_memoryCache = memoryCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult OnGet()
|
public IActionResult OnGet()
|
||||||
|
{
|
||||||
|
if (!_memoryCache.TryGetValue("Sitemap", out string sitemapXml))
|
||||||
{
|
{
|
||||||
var sitemap = new List<Sitemap>();
|
var sitemap = new List<Sitemap>();
|
||||||
|
|
||||||
|
@ -108,8 +113,11 @@ namespace Oqtane.Pages
|
||||||
}
|
}
|
||||||
writer.Close();
|
writer.Close();
|
||||||
}
|
}
|
||||||
|
// Cache the sitemap XML
|
||||||
return Content(builder.ToString());
|
sitemapXml = builder.ToString();
|
||||||
|
_memoryCache.Set("Sitemap", sitemapXml, TimeSpan.FromHours(1));
|
||||||
|
}
|
||||||
|
return Content(sitemapXml, "application/xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user