Skip to content

Commit

Permalink
Fix internal class being returned from media cache service (#17213)
Browse files Browse the repository at this point in the history
* update backoffice submodule

* update backoffice submodule

* Fix internal class being returned from media cache service

Return the correct models from the media cache service

---------

Co-authored-by: Jacob Overgaard <[email protected]>

(cherry picked from commit ccd02cf)
  • Loading branch information
matthewcare authored and bergmania committed Oct 9, 2024
1 parent a73fef1 commit ea073e6
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
Expand All @@ -8,6 +8,7 @@
using Umbraco.Cms.Infrastructure.HybridCache.Factories;
using Umbraco.Cms.Infrastructure.HybridCache.Persistence;
using Umbraco.Cms.Infrastructure.HybridCache.Serialization;
using Umbraco.Extensions;

namespace Umbraco.Cms.Infrastructure.HybridCache.Services;

Expand All @@ -20,6 +21,7 @@ internal class MediaCacheService : IMediaCacheService
private readonly IPublishedContentFactory _publishedContentFactory;
private readonly ICacheNodeFactory _cacheNodeFactory;
private readonly IEnumerable<IMediaSeedKeyProvider> _seedKeyProviders;
private readonly IPublishedModelFactory _publishedModelFactory;
private readonly CacheSettings _cacheSettings;

private HashSet<Guid>? _seedKeys;
Expand Down Expand Up @@ -51,6 +53,7 @@ public MediaCacheService(
IPublishedContentFactory publishedContentFactory,
ICacheNodeFactory cacheNodeFactory,
IEnumerable<IMediaSeedKeyProvider> seedKeyProviders,
IPublishedModelFactory publishedModelFactory,
IOptions<CacheSettings> cacheSettings)
{
_databaseCacheRepository = databaseCacheRepository;
Expand All @@ -60,6 +63,7 @@ public MediaCacheService(
_publishedContentFactory = publishedContentFactory;
_cacheNodeFactory = cacheNodeFactory;
_seedKeyProviders = seedKeyProviders;
_publishedModelFactory = publishedModelFactory;
_cacheSettings = cacheSettings.Value;
}

Expand All @@ -78,7 +82,7 @@ public MediaCacheService(
async cancel => await _databaseCacheRepository.GetMediaSourceAsync(idAttempt.Result));

scope.Complete();
return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode);
return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode).CreateModel(_publishedModelFactory);
}

public async Task<IPublishedContent?> GetByIdAsync(int id)
Expand All @@ -94,7 +98,7 @@ public MediaCacheService(
$"{keyAttempt.Result}", // Unique key to the cache entry
async cancel => await _databaseCacheRepository.GetMediaSourceAsync(id));
scope.Complete();
return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode);
return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode).CreateModel(_publishedModelFactory);
}

public async Task<bool> HasContentByIdAsync(int id)
Expand Down Expand Up @@ -144,7 +148,7 @@ public async Task SeedAsync(CancellationToken cancellationToken)

foreach (Guid key in SeedKeys)
{
if(cancellationToken.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
{
break;
}
Expand Down Expand Up @@ -187,7 +191,8 @@ public void Rebuild(IReadOnlyCollection<int> contentTypeIds)

private HybridCacheEntryOptions GetSeedEntryOptions() => new()
{
Expiration = _cacheSettings.SeedCacheDuration, LocalCacheExpiration = _cacheSettings.SeedCacheDuration,
Expiration = _cacheSettings.SeedCacheDuration,
LocalCacheExpiration = _cacheSettings.SeedCacheDuration,
};

private string GetCacheKey(Guid key, bool preview) => preview ? $"{key}+draft" : $"{key}";
Expand Down

0 comments on commit ea073e6

Please sign in to comment.