diff --git a/src/Umbraco.Cms.Api.Management/DependencyInjection/DashboardBuilderExtensions.cs b/src/Umbraco.Cms.Api.Management/DependencyInjection/DashboardBuilderExtensions.cs index 914546a6d0..9d5f4ebedc 100644 --- a/src/Umbraco.Cms.Api.Management/DependencyInjection/DashboardBuilderExtensions.cs +++ b/src/Umbraco.Cms.Api.Management/DependencyInjection/DashboardBuilderExtensions.cs @@ -8,8 +8,10 @@ internal static class NewsDashboardBuilderExtensions { internal static IUmbracoBuilder AddNewsDashboard(this IUmbracoBuilder builder) { + builder.Services.AddSingleton(); builder.Services.AddSingleton(); return builder; } } + diff --git a/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/INewsCacheDurationProvider.cs b/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/INewsCacheDurationProvider.cs new file mode 100644 index 0000000000..e55f00cc0e --- /dev/null +++ b/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/INewsCacheDurationProvider.cs @@ -0,0 +1,12 @@ +namespace Umbraco.Cms.Api.Management.Services.NewsDashboard; + +/// +/// Cache duration provider for the news dashboard service. +/// +public interface INewsCacheDurationProvider +{ + /// + /// Gets the cache duration for news dashboard items. + /// + TimeSpan CacheDuration { get; } +} diff --git a/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsCacheDurationProvider.cs b/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsCacheDurationProvider.cs new file mode 100644 index 0000000000..82ead02fd4 --- /dev/null +++ b/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsCacheDurationProvider.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Cms.Api.Management.Services.NewsDashboard; + +public class NewsCacheDurationProvider : INewsCacheDurationProvider +{ + /// + public TimeSpan CacheDuration => TimeSpan.FromMinutes(30); +} diff --git a/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsDashboardService.cs b/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsDashboardService.cs index 6dfe7fde54..91210c082d 100644 --- a/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsDashboardService.cs +++ b/src/Umbraco.Cms.Api.Management/Services/NewsDashboard/NewsDashboardService.cs @@ -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; @@ -21,6 +23,7 @@ public class NewsDashboardService : INewsDashboardService private readonly ILogger _logger; private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; private readonly GlobalSettings _globalSettings; + private readonly INewsCacheDurationProvider _newsCacheDurationProvider; private static readonly HttpClient _httpClient = new(); @@ -33,7 +36,8 @@ public class NewsDashboardService : INewsDashboardService ISiteIdentifierService siteIdentifierService, ILogger logger, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - IOptions globalSettings) + IOptions globalSettings, + INewsCacheDurationProvider newsCacheDurationProvider) { _appCaches = appCaches; _umbracoVersion = umbracoVersion; @@ -41,6 +45,26 @@ public class NewsDashboardService : INewsDashboardService _logger = logger; _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _globalSettings = globalSettings.Value; + _newsCacheDurationProvider = newsCacheDurationProvider; + } + + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 19")] + public NewsDashboardService( + AppCaches appCaches, + IUmbracoVersion umbracoVersion, + ISiteIdentifierService siteIdentifierService, + ILogger logger, + IBackOfficeSecurityAccessor backOfficeSecurityAccessor, + IOptions globalSettings) + : this( + appCaches, + umbracoVersion, + siteIdentifierService, + logger, + backOfficeSecurityAccessor, + globalSettings, + StaticServiceProvider.Instance.GetRequiredService()) + { } /// @@ -69,7 +93,7 @@ public class NewsDashboardService : INewsDashboardService if (TryMapModel(json, out NewsDashboardResponseModel? model)) { - _appCaches.RuntimeCache.InsertCacheItem(CacheKey, () => model, new TimeSpan(0, 30, 0)); + _appCaches.RuntimeCache.InsertCacheItem(CacheKey, () => model, _newsCacheDurationProvider.CacheDuration); content = model; } }