1- using Microsoft . Extensions . Logging ;
2- using Umbraco . Cms . Core . Cache ;
31using Umbraco . Cms . Core . Extensions ;
42using Umbraco . Cms . Core . Models ;
53using Umbraco . Cms . Core . Models . PublishedContent ;
64using Umbraco . Cms . Core . PublishedCache ;
7- using Umbraco . Extensions ;
85
96namespace Umbraco . Cms . Infrastructure . HybridCache . Factories ;
107
@@ -16,49 +13,23 @@ internal sealed class PublishedContentFactory : IPublishedContentFactory
1613 private readonly IElementsCache _elementsCache ;
1714 private readonly IVariationContextAccessor _variationContextAccessor ;
1815 private readonly IPublishedContentTypeCache _publishedContentTypeCache ;
19- private readonly ILogger < PublishedContentFactory > _logger ;
20- private readonly AppCaches _appCaches ;
2116
2217 /// <summary>
2318 /// Initializes a new instance of the <see cref="PublishedContentFactory"/> class.
2419 /// </summary>
2520 public PublishedContentFactory (
2621 IElementsCache elementsCache ,
2722 IVariationContextAccessor variationContextAccessor ,
28- IPublishedContentTypeCache publishedContentTypeCache ,
29- ILogger < PublishedContentFactory > logger ,
30- AppCaches appCaches )
23+ IPublishedContentTypeCache publishedContentTypeCache )
3124 {
3225 _elementsCache = elementsCache ;
3326 _variationContextAccessor = variationContextAccessor ;
3427 _publishedContentTypeCache = publishedContentTypeCache ;
35- _logger = logger ;
36- _appCaches = appCaches ;
3728 }
3829
3930 /// <inheritdoc/>
4031 public IPublishedContent ? ToIPublishedContent ( ContentCacheNode contentCacheNode , bool preview )
4132 {
42- var cacheKey = $ "{ nameof ( PublishedContentFactory ) } DocumentCache_{ contentCacheNode . Id } _{ preview } _{ contentCacheNode . Data ? . VersionDate . Ticks ?? 0 } ";
43- IPublishedContent ? publishedContent = null ;
44- if ( _appCaches . RequestCache . IsAvailable )
45- {
46- publishedContent = _appCaches . RequestCache . GetCacheItem < IPublishedContent ? > ( cacheKey ) ;
47- if ( publishedContent is not null )
48- {
49- _logger . LogDebug (
50- "Using cached IPublishedContent for document {ContentCacheNodeName} ({ContentCacheNodeId})." ,
51- contentCacheNode . Data ? . Name ?? "No Name" ,
52- contentCacheNode . Id ) ;
53- return publishedContent ;
54- }
55- }
56-
57- _logger . LogDebug (
58- "Creating IPublishedContent for document {ContentCacheNodeName} ({ContentCacheNodeId})." ,
59- contentCacheNode . Data ? . Name ?? "No Name" ,
60- contentCacheNode . Id ) ;
61-
6233 IPublishedContentType contentType =
6334 _publishedContentTypeCache . Get ( PublishedItemType . Content , contentCacheNode . ContentTypeId ) ;
6435 var contentNode = new ContentNode (
@@ -71,44 +42,19 @@ public PublishedContentFactory(
7142 preview ? contentCacheNode . Data : null ,
7243 preview ? null : contentCacheNode . Data ) ;
7344
74- publishedContent = GetModel ( contentNode , preview ) ;
45+ IPublishedContent ? publishedContent = GetModel ( contentNode , preview ) ;
7546
7647 if ( preview )
7748 {
7849 publishedContent ??= GetPublishedContentAsDraft ( publishedContent ) ;
7950 }
8051
81- if ( _appCaches . RequestCache . IsAvailable && publishedContent is not null )
82- {
83- _appCaches . RequestCache . Set ( cacheKey , publishedContent ) ;
84- }
85-
8652 return publishedContent ;
8753 }
8854
8955 /// <inheritdoc/>
9056 public IPublishedContent ? ToIPublishedMedia ( ContentCacheNode contentCacheNode )
9157 {
92- var cacheKey = $ "{ nameof ( PublishedContentFactory ) } MediaCache_{ contentCacheNode . Id } ";
93- IPublishedContent ? publishedContent = null ;
94- if ( _appCaches . RequestCache . IsAvailable )
95- {
96- publishedContent = _appCaches . RequestCache . GetCacheItem < IPublishedContent ? > ( cacheKey ) ;
97- if ( publishedContent is not null )
98- {
99- _logger . LogDebug (
100- "Using cached IPublishedContent for media {ContentCacheNodeName} ({ContentCacheNodeId})." ,
101- contentCacheNode . Data ? . Name ?? "No Name" ,
102- contentCacheNode . Id ) ;
103- return publishedContent ;
104- }
105- }
106-
107- _logger . LogDebug (
108- "Creating IPublishedContent for media {ContentCacheNodeName} ({ContentCacheNodeId})." ,
109- contentCacheNode . Data ? . Name ?? "No Name" ,
110- contentCacheNode . Id ) ;
111-
11258 IPublishedContentType contentType =
11359 _publishedContentTypeCache . Get ( PublishedItemType . Media , contentCacheNode . ContentTypeId ) ;
11460 var contentNode = new ContentNode (
@@ -121,40 +67,12 @@ public PublishedContentFactory(
12167 null ,
12268 contentCacheNode . Data ) ;
12369
124- publishedContent = GetModel ( contentNode , false ) ;
125-
126- if ( _appCaches . RequestCache . IsAvailable && publishedContent is not null )
127- {
128- _appCaches . RequestCache . Set ( cacheKey , publishedContent ) ;
129- }
130-
131- return publishedContent ;
70+ return GetModel ( contentNode , false ) ;
13271 }
13372
13473 /// <inheritdoc/>
13574 public IPublishedMember ToPublishedMember ( IMember member )
13675 {
137- string cacheKey = $ "{ nameof ( PublishedContentFactory ) } MemberCache_{ member . Id } ";
138- IPublishedMember ? publishedMember = null ;
139- if ( _appCaches . RequestCache . IsAvailable )
140- {
141- publishedMember = _appCaches . RequestCache . GetCacheItem < IPublishedMember ? > ( cacheKey ) ;
142- if ( publishedMember is not null )
143- {
144- _logger . LogDebug (
145- "Using cached IPublishedMember for member {MemberName} ({MemberId})." ,
146- member . Username ,
147- member . Id ) ;
148-
149- return publishedMember ;
150- }
151- }
152-
153- _logger . LogDebug (
154- "Creating IPublishedMember for member {MemberName} ({MemberId})." ,
155- member . Username ,
156- member . Id ) ;
157-
15876 IPublishedContentType contentType =
15977 _publishedContentTypeCache . Get ( PublishedItemType . Member , member . ContentTypeId ) ;
16078
@@ -179,14 +97,7 @@ public IPublishedMember ToPublishedMember(IMember member)
17997 contentType ,
18098 null ,
18199 contentData ) ;
182- publishedMember = new PublishedMember ( member , contentNode , _elementsCache , _variationContextAccessor ) ;
183-
184- if ( _appCaches . RequestCache . IsAvailable )
185- {
186- _appCaches . RequestCache . Set ( cacheKey , publishedMember ) ;
187- }
188-
189- return publishedMember ;
100+ return new PublishedMember ( member , contentNode , _elementsCache , _variationContextAccessor ) ;
190101 }
191102
192103 private static Dictionary < string , PropertyData [ ] > GetPropertyValues ( IPublishedContentType contentType , IMember member )
0 commit comments