Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal static class NewsDashboardBuilderExtensions
{
internal static IUmbracoBuilder AddNewsDashboard(this IUmbracoBuilder builder)
{
builder.Services.AddSingleton<NewsDashboardOptions>();
builder.Services.AddSingleton<INewsDashboardService, NewsDashboardService>();

return builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Umbraco.Cms.Api.Management.Services.NewsDashboard;

/// <summary>
/// Options for the news dashboard service.
/// </summary>
public class NewsDashboardOptions
{
/// <summary>
/// Gets the cache duration for news dashboard items.
/// </summary>
public virtual TimeSpan CacheDuration => TimeSpan.FromMinutes(30);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Api.Management.ViewModels.NewsDashboard;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Telemetry;
using Umbraco.Extensions;
Expand All @@ -21,6 +23,7 @@ public class NewsDashboardService : INewsDashboardService
private readonly ILogger<NewsDashboardService> _logger;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly GlobalSettings _globalSettings;
private readonly NewsDashboardOptions _newsDashboardOptions;

private static readonly HttpClient _httpClient = new();

Expand All @@ -33,14 +36,35 @@ public NewsDashboardService(
ISiteIdentifierService siteIdentifierService,
ILogger<NewsDashboardService> logger,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IOptions<GlobalSettings> globalSettings)
IOptions<GlobalSettings> globalSettings,
NewsDashboardOptions newsDashboardOptions)
{
_appCaches = appCaches;
_umbracoVersion = umbracoVersion;
_siteIdentifierService = siteIdentifierService;
_logger = logger;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_globalSettings = globalSettings.Value;
_newsDashboardOptions = newsDashboardOptions;
}

[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 19")]
public NewsDashboardService(
AppCaches appCaches,
IUmbracoVersion umbracoVersion,
ISiteIdentifierService siteIdentifierService,
ILogger<NewsDashboardService> logger,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IOptions<GlobalSettings> globalSettings)
: this(
appCaches,
umbracoVersion,
siteIdentifierService,
logger,
backOfficeSecurityAccessor,
globalSettings,
StaticServiceProvider.Instance.GetRequiredService<NewsDashboardOptions>())
{
}

/// <inheritdoc />
Expand Down Expand Up @@ -69,7 +93,7 @@ public async Task<NewsDashboardResponseModel> GetItemsAsync()

if (TryMapModel(json, out NewsDashboardResponseModel? model))
{
_appCaches.RuntimeCache.InsertCacheItem(CacheKey, () => model, new TimeSpan(0, 30, 0));
_appCaches.RuntimeCache.InsertCacheItem(CacheKey, () => model, _newsDashboardOptions.CacheDuration);
content = model;
}
}
Expand Down
Loading