Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15 QA Hybrid Cache added media cache tests and fixed media cache refreshing #17160

Merged
merged 268 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
268 commits
Select commit Hold shift + click to select a range
5770a39
Add cache refresher
Zeegaan Jul 4, 2024
9c2b836
make public as needed for serialization
Zeegaan Jul 4, 2024
437497f
Use content type cache to get content type out
Zeegaan Jul 5, 2024
1c035c0
Refactor to use ContentCacheNode model, that goes in the memory cache
Zeegaan Jul 5, 2024
661bb32
Remove content node kit as its not needed
Zeegaan Jul 5, 2024
1002a5d
Implement tests for ensuring caching
Zeegaan Jul 8, 2024
22c68ff
Implement better asserts
Zeegaan Jul 9, 2024
65e596d
Implement published property
Zeegaan Jul 9, 2024
04dbde3
Refactor to use mapping
Zeegaan Jul 9, 2024
0c7a7e2
Rename to document tests
Zeegaan Jul 9, 2024
42b427e
Update to test properties
Zeegaan Jul 9, 2024
a75c463
Create more tests
Zeegaan Jul 10, 2024
acb745a
Refactor mock tests into own file
Zeegaan Jul 10, 2024
0465971
Update property test
Zeegaan Jul 10, 2024
8233de8
Fix published version of content
Zeegaan Jul 10, 2024
f87181a
Change default cache level to elements
Zeegaan Jul 10, 2024
b82eb60
Refactor to always have draft
Zeegaan Jul 10, 2024
fa15a2e
Refactor to not use PublishedModelFactory
Zeegaan Jul 10, 2024
7149fd8
Added tests
andr317c Jul 10, 2024
a5bb8ae
Added and updated tests
andr317c Jul 10, 2024
4d10def
Fixed tests
andr317c Jul 11, 2024
5a7d435
Don't return empty object with id
Zeegaan Jul 11, 2024
4a73539
More tests
andr317c Jul 11, 2024
a7203f8
Added key
andr317c Jul 11, 2024
7c6b5e1
Another key
andr317c Jul 11, 2024
4151d9f
Refactor CacheService to be responsible for using the hybrid cache
Zeegaan Jul 12, 2024
08bdb8e
Use notification handler to remove deleted content from cache
Zeegaan Jul 12, 2024
26b209f
Add more tests for missing functions
Zeegaan Jul 12, 2024
55341f7
Implement missing methods
Zeegaan Jul 12, 2024
4750985
Remove HasContent as it pertains to routing
Zeegaan Jul 15, 2024
c3c017e
Fik up test
Zeegaan Jul 15, 2024
895e324
formatting
Zeegaan Jul 15, 2024
f9e5276
refactor variable names
Zeegaan Jul 15, 2024
4191c3a
Implement variant tests
Zeegaan Jul 15, 2024
b714596
Map all the published content properties
Zeegaan Jul 15, 2024
197c2ca
Get item out of cache first, to assert updated
Zeegaan Jul 16, 2024
dc22674
Implement member cache
Zeegaan Jul 16, 2024
0c9dad6
Add member test
Zeegaan Jul 16, 2024
4c941bb
Implement media cache
Zeegaan Jul 16, 2024
f03485a
Implement property tests for media tests
Zeegaan Jul 17, 2024
387628c
Refactor tests to use extension method
Zeegaan Jul 17, 2024
7ed8c94
Add more media tests
Zeegaan Jul 17, 2024
1dfd5a7
Refactor properties to no longer have element caching
Zeegaan Jul 18, 2024
6b2b978
Don't use property cache level
Zeegaan Jul 18, 2024
9eab933
Start implementing seeding
Zeegaan Jul 22, 2024
97c7d08
Only seed when main
Zeegaan Jul 22, 2024
33483e6
Add Immutable for performance
Zeegaan Jul 22, 2024
47b6e88
Implement permanent seeding of content
Zeegaan Jul 22, 2024
acae74c
Implement cache settings
Zeegaan Jul 22, 2024
b64ade1
Implement tests for seeding
Zeegaan Jul 22, 2024
632f0ce
Update package version
Zeegaan Jul 23, 2024
905790e
start refactoring nurepo
Zeegaan Jul 25, 2024
026b88b
Merge remote-tracking branch 'origin/v15/feature/hybrid-caching' into…
Zeegaan Jul 25, 2024
61ce2cf
Refactor so draft & published nodes are cached individually
Zeegaan Jul 25, 2024
c2b7879
Refactor RefreshContent to take node instead of IContent
Zeegaan Jul 25, 2024
ab2fce3
Refactor media to also use cache nodes
Zeegaan Jul 26, 2024
fab1df8
Remove member from repo as it isn't cached
Zeegaan Jul 26, 2024
1bb1601
Refactor media to not include preview, as media has no draft
Zeegaan Jul 26, 2024
617ebf0
create new benchmark project
Zeegaan Aug 2, 2024
56dd31c
POC Integration benchmarks with custom api controllers
Migaroez Aug 2, 2024
3b3de87
Merge branch 'v14/dev' into v15/feature/hybrid-caching
Zeegaan Aug 7, 2024
8eef9ce
Start implementing content picker tests
Zeegaan Aug 14, 2024
4807241
Implement domain cache
Zeegaan Aug 15, 2024
6788066
Rework content cache to implement interface
Zeegaan Aug 15, 2024
6b98d8f
Start implementing elements cache
Zeegaan Aug 15, 2024
f12eb47
Implement published snapshot service
Zeegaan Aug 15, 2024
8152c19
Publish snapshot tests
Zeegaan Aug 15, 2024
2bc59e3
Use snapshot for elements cache
Zeegaan Aug 19, 2024
ea93843
Create test proving we don't clear cache when updating content picker
Zeegaan Aug 19, 2024
e7c86cc
Clear entire elements cache
Zeegaan Aug 19, 2024
b3aa4d3
Remove properties from element cache, when content gets updated.
Zeegaan Aug 20, 2024
4b34ac5
Merge remote-tracking branch 'origin/v15/dev' into v15/feature/hybrid…
Zeegaan Aug 21, 2024
69e0324
Rename methods to async
Zeegaan Aug 21, 2024
06d71b4
Refactor to use old cache interfaces instead of new ones
Zeegaan Aug 21, 2024
4b4ff31
Remove snapshot, as it is no longer needed
Zeegaan Aug 21, 2024
27b1202
Fix tests building
Zeegaan Aug 21, 2024
0fe3ed5
Refactor domaincache to not have snapshots
Zeegaan Aug 22, 2024
640b9be
Delete benchmarks
Zeegaan Aug 22, 2024
824a530
Delete benchmarks
Zeegaan Aug 22, 2024
513d08a
Merge remote-tracking branch 'origin/v15/feature/hybrid-caching' into…
Zeegaan Aug 22, 2024
dfaf285
Add HybridCacheProject to Umbraco
Zeegaan Aug 22, 2024
6630b7d
Add comment to route value transformer
Zeegaan Aug 22, 2024
89cb8ff
Implement is draft
Zeegaan Aug 22, 2024
b2bd81a
remove snapshot from property
Zeegaan Aug 22, 2024
0e9067d
V15 updated the hybrid caching integration tests to use ContentEditin…
andr317c Aug 22, 2024
5d373ce
Merge remote-tracking branch 'origin/v15/feature/hybrid-caching' into…
Zeegaan Aug 22, 2024
9e5eed3
Remove entries from cache on delete
Zeegaan Aug 22, 2024
eeb8863
Fix up seeding logic
Zeegaan Aug 22, 2024
9510e03
Don't register hybrid cache twice
Zeegaan Aug 23, 2024
0fe27e2
Change seeded entry options
Zeegaan Aug 23, 2024
2573115
Update hybrid cache package
Zeegaan Aug 23, 2024
0fbd157
Fix up published property to work with delivery api again
Zeegaan Aug 24, 2024
a2c1fc4
Fix dependency injection to work with tests
Zeegaan Aug 26, 2024
d5dd217
Fix naming
nikolajlauridsen Aug 26, 2024
182c17a
Dont make caches nullable
Zeegaan Aug 27, 2024
ceb74b7
Make content node sealed
Zeegaan Aug 27, 2024
e62f24a
Remove path and other unused from content node
Zeegaan Aug 27, 2024
81134ad
Remove hacky 2 phase ctor
Zeegaan Aug 27, 2024
3ae0595
Refactor to actually set content templates
Zeegaan Aug 27, 2024
6d4a20f
Remove umbraco context
Zeegaan Aug 27, 2024
e9e3023
Remove "HasBy" methods
Zeegaan Aug 27, 2024
cdfe257
rename property data
Zeegaan Aug 27, 2024
d370f99
Delete obsolete legacy stuff
Zeegaan Aug 27, 2024
c03dfb6
Add todo for making expiration configurable
Zeegaan Aug 27, 2024
73ace33
Add todo in UmbracoContext
Zeegaan Aug 27, 2024
d881eec
Add clarifying comment in content factory
Zeegaan Aug 27, 2024
8f275ec
Remove xml stuff from published property
Zeegaan Aug 27, 2024
32e749d
Fix according to review
Zeegaan Aug 27, 2024
6af5487
Merge remote-tracking branch 'origin/v15/dev' into v15/feature/hybrid…
Zeegaan Aug 27, 2024
5851239
Make content type cache injectible
Zeegaan Aug 27, 2024
8f68e09
Make content type cache injectible
Zeegaan Aug 27, 2024
6e2d817
Merge branch 'v15/feature/hybrid-caching' of https://github.com/umbra…
Zeegaan Aug 27, 2024
202dee5
Rename to database cache repository
Zeegaan Aug 27, 2024
86f4be2
Rename to document cache
Zeegaan Aug 27, 2024
df9d221
Add TODO
nikolajlauridsen Aug 28, 2024
e8a2c57
Refactor to async
Zeegaan Aug 28, 2024
3705855
Merge remote-tracking branch 'origin/v15/feature/hybrid-caching' into…
Zeegaan Aug 28, 2024
ea39b43
Rename to async
Zeegaan Aug 28, 2024
065979c
Make everything async
Zeegaan Aug 28, 2024
df9f3c2
Remove duplicate line from json schema
Zeegaan Aug 28, 2024
ce732f2
Move Hybrid cache project
Zeegaan Aug 28, 2024
6a00a53
Remove leftover file
nikolajlauridsen Aug 28, 2024
1d65aeb
Refactor to use keys
Zeegaan Aug 28, 2024
184c19a
Merge remote-tracking branch 'origin/v15/dev' into v15/feature/hybrid…
Zeegaan Aug 28, 2024
9c2350b
Refactor published content to no longer have content data, as it is o…
Zeegaan Aug 28, 2024
59f7257
Refactor to member to use proper content node ctor
Zeegaan Aug 28, 2024
9830e23
Move tests to own folder
Zeegaan Aug 28, 2024
8a675d9
Add immutable objects to property and content data for performance
Zeegaan Aug 28, 2024
63cf4fd
Make property data public
Zeegaan Aug 28, 2024
bbd7300
Fix member caching to be singleton
Zeegaan Aug 28, 2024
2cd7ad3
Obsolete GetContentType
Zeegaan Aug 28, 2024
b59e56a
Remove todo
Zeegaan Aug 28, 2024
c941b29
Fix naming
Zeegaan Aug 28, 2024
38e337a
Fix lots of exposed errors due to scope test
Zeegaan Aug 28, 2024
101e253
Add final scope tests
Zeegaan Aug 28, 2024
38d6b11
Rename to document cache service
Zeegaan Aug 29, 2024
86a5a64
Rename test files
Zeegaan Aug 30, 2024
e45fa10
Create new doc type tests
Zeegaan Aug 30, 2024
1ad0b68
Add ignore to tests
Zeegaan Aug 30, 2024
01d48bd
Merge remote-tracking branch 'origin/v15/dev' into v15/feature/hybrid…
Zeegaan Aug 30, 2024
af4f2de
Start implementing refresh for content type save
Zeegaan Aug 30, 2024
bfae478
Clear contenttype cache when contenttype is updated
nikolajlauridsen Sep 3, 2024
73d0523
Fix test
nikolajlauridsen Sep 3, 2024
0693950
Updated tests
andr317c Sep 3, 2024
ee6aaee
Added tests
andr317c Sep 3, 2024
f90c8f4
Use init for ContentSourceDto
nikolajlauridsen Sep 4, 2024
75512dc
Startup of setup
andr317c Sep 4, 2024
d925f52
Fix get by key in PublishedContentTypeCache
nikolajlauridsen Sep 4, 2024
d06de4d
Remove ContentType from PublishedContentTypeCache when contenttype is…
nikolajlauridsen Sep 4, 2024
3ebf3f2
Created interfaces for the builder with the necessary properties
andr317c Sep 5, 2024
6f12fc6
Created builder for PropertyTypeContainer
andr317c Sep 5, 2024
f983dfc
Created builder for PropertyTypeEditing
andr317c Sep 5, 2024
152469a
Created builder for PropertyTypeValidationEditing
andr317c Sep 5, 2024
5378590
Made adjustments to the builder
andr317c Sep 5, 2024
6a339b0
Updated name of usage
andr317c Sep 5, 2024
9d80212
Commented out to test
andr317c Sep 5, 2024
2b99318
Merge remote-tracking branch 'refs/remotes/origin/v15/feature/hybrid-…
andr317c Sep 5, 2024
8a0c3f8
Cleaned up builders
andr317c Sep 5, 2024
373cd2e
Updated integration test setup
andr317c Sep 5, 2024
69e1837
Moved tests
andr317c Sep 5, 2024
4b5a1e6
Merge remote-tracking branch 'refs/remotes/origin/v15/dev' into v15/f…
nikolajlauridsen Sep 6, 2024
7268e47
Merge remote-tracking branch 'origin/v15/feature/hybrid-caching' into…
andr317c Sep 6, 2024
8181e09
Added interface
andr317c Sep 6, 2024
bf64d69
Add IDocumentSeedKeyProvider and migrate existing logic to seed key p…
nikolajlauridsen Sep 10, 2024
7ef707b
Added functionality to the INavigationQueryService to get root keys
bergmania Sep 4, 2024
34927ae
Fixed issue with navigation
bergmania Sep 9, 2024
8b0f8ed
Created helper to Convert a IContentType to ContentTypeUpdateModel
andr317c Sep 10, 2024
d0070c5
Added interfaces
andr317c Sep 10, 2024
8038db2
Added builder
andr317c Sep 10, 2024
75ca1a9
Cleaned up builders and added fixes
andr317c Sep 10, 2024
5a2a1d4
Added tests for PublishedContentTypeCache
andr317c Sep 10, 2024
c51de5e
Applied changes in builder
andr317c Sep 10, 2024
a274faa
Add BreadthFirstKeyProvider
nikolajlauridsen Sep 10, 2024
334d540
Use ISet for seedkey providers
nikolajlauridsen Sep 11, 2024
8802a16
Implement GetContentSource by key
nikolajlauridsen Sep 11, 2024
6304f5d
Seed the cache with keys provided by seed key providers
nikolajlauridsen Sep 11, 2024
65371c5
Builder updates
andr317c Sep 11, 2024
89c847d
Test setup updates
andr317c Sep 11, 2024
08d0162
Updated tests
andr317c Sep 11, 2024
0709262
Merge branch 'v15/dev' into v15/feature/cache-seeding
nikolajlauridsen Sep 16, 2024
4e6043b
Dont require contenttype keys for seeding
nikolajlauridsen Sep 16, 2024
90626c3
Fix cache settings
nikolajlauridsen Sep 16, 2024
098265c
Don't inject cache settings into SeedingNotificationHandler
nikolajlauridsen Sep 16, 2024
ffba7bb
Fix tests
nikolajlauridsen Sep 16, 2024
d59558c
Use enlistment for setting updated cache item
nikolajlauridsen Sep 16, 2024
6c71a59
Pin seeded nodes for longer
nikolajlauridsen Sep 17, 2024
2678915
Fix BreadthFirstKeyProvider
nikolajlauridsen Sep 17, 2024
ba01b2d
Fix ContentTypeSeedKeyProvider
nikolajlauridsen Sep 17, 2024
2a66669
Fix tests
nikolajlauridsen Sep 17, 2024
e74902f
Only seed published documents
nikolajlauridsen Sep 18, 2024
c08287e
Merge remote-tracking branch 'origin/v15/feature/cache-seeding' into …
andr317c Sep 18, 2024
afa1143
Merge remote-tracking branch 'origin/v15/dev' into v15/QA/hybrid-cach…
andr317c Sep 18, 2024
e0623d0
Only cache published if contentCacheNode is not draft
nikolajlauridsen Sep 18, 2024
da84756
Fix incorrect templateId
nikolajlauridsen Sep 18, 2024
55cb11b
Merge remote-tracking branch 'refs/remotes/origin/v15/feature/cache-s…
andr317c Sep 18, 2024
6908c68
Removed unnecessary setup
andr317c Sep 18, 2024
5e31593
initialized value
andr317c Sep 18, 2024
d90257e
Fixed template test
andr317c Sep 18, 2024
403f45e
Removed test
andr317c Sep 18, 2024
466ff82
Merge remote-tracking branch 'origin/v15/dev' into v15/feature/cache-…
nikolajlauridsen Sep 18, 2024
6d89d31
Merge remote-tracking branch 'origin/v15/feature/cache-seeding' into …
andr317c Sep 18, 2024
b595ec5
Updated tests
andr317c Sep 18, 2024
71b6c74
Removed code that was not used
andr317c Sep 18, 2024
34810f0
Removed unused cacheSettings
andr317c Sep 19, 2024
62b8a56
Re-organize to support media cache seeding
nikolajlauridsen Sep 19, 2024
e45f46e
Add MediaBreadthFirstKeyProvider
nikolajlauridsen Sep 19, 2024
cdc88ba
Seed media
nikolajlauridsen Sep 19, 2024
a481f4d
Don't use IdKeyMap when removing content from cache
nikolajlauridsen Sep 19, 2024
92b9e24
Merge remote-tracking branch 'refs/remotes/origin/v15/feature/cache-s…
andr317c Sep 19, 2024
847dc3e
Don't clear IdKeyMap in DocumentCacheService
nikolajlauridsen Sep 19, 2024
714e446
Merge pull request #17095 from umbraco/v15/QA/hybrid-caching-tests
nikolajlauridsen Sep 19, 2024
15538c6
Add unit tests
nikolajlauridsen Sep 19, 2024
be9bc37
Don't use IdKeyMap when deleting media
nikolajlauridsen Sep 20, 2024
af718e7
Add default value to timespan
bergmania Sep 23, 2024
8a3ac89
Use cancellation tokens when doing loop
bergmania Sep 23, 2024
86c1400
Fixed Models Builder error
bergmania Sep 24, 2024
8f37d18
Builder testing
andr317c Sep 25, 2024
d5fd056
Media test
andr317c Sep 25, 2024
3d360eb
Created builders
andr317c Sep 26, 2024
a744411
Updated method from getByKey to getById to maintain structure
andr317c Sep 26, 2024
9d09b97
Updated test setup
andr317c Sep 26, 2024
5288f68
Moved tests
andr317c Sep 29, 2024
6807243
Cleaned up builders
andr317c Sep 29, 2024
b53d967
Added helper
andr317c Sep 29, 2024
2872893
Added space
andr317c Sep 29, 2024
b3b6da3
Updated tests
andr317c Sep 29, 2024
d8da187
Cleaned setup
andr317c Sep 29, 2024
6f00119
Added tests for MediaTypes
andr317c Sep 29, 2024
7e0f0a8
Uncommented tests
andr317c Sep 29, 2024
bc616da
Added builder extensions
andr317c Sep 30, 2024
cf1ed0e
Added interfaces for builder methods
andr317c Sep 30, 2024
c3d41d2
Updated to use interface pattern
andr317c Sep 30, 2024
747c768
Updated name
andr317c Sep 30, 2024
afa22fa
Used builder
andr317c Sep 30, 2024
0459a37
Cleaned up test
andr317c Sep 30, 2024
93fd267
Added media scope tests
andr317c Sep 30, 2024
882a49f
Merge remote-tracking branch 'origin/v15/dev' into v15/QA/media-cache…
andr317c Sep 30, 2024
c1d1621
Removed PropertyTypeModelBuilder
andr317c Sep 30, 2024
f272b5f
moved PropertyTypeModelBuilder to PropertyTypeEditingBuilder
andr317c Sep 30, 2024
9f24038
Removed constructor
andr317c Sep 30, 2024
2ccba00
Removed duplicate
andr317c Sep 30, 2024
9de4483
Fixed naming
andr317c Sep 30, 2024
6b2440e
Reverted
andr317c Sep 30, 2024
b96caaa
Removed space
andr317c Sep 30, 2024
71c48cf
Merge remote-tracking branch 'refs/remotes/origin/v15/dev' into v15/Q…
andr317c Oct 2, 2024
34f467b
Added todos
andr317c Oct 2, 2024
ce73bdb
Removed only run on linux
andr317c Oct 2, 2024
5180ca3
Commet out DocumentHybridCacheTemplateTest again
nikolajlauridsen Oct 2, 2024
b4de535
Update media when media type is updated
nikolajlauridsen Oct 2, 2024
c9d561d
Remove todo the tests pass now
nikolajlauridsen Oct 2, 2024
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
2 changes: 1 addition & 1 deletion src/Umbraco.Core/PublishedCache/IPublishedMediaCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public interface IPublishedMediaCache : IPublishedCache
/// <param name="key">The content unique identifier.</param>
/// <returns>The content, or null.</returns>
/// <remarks>Considers published or unpublished content depending on defaults.</remarks>
Task<IPublishedContent?> GetByKeyAsync(Guid key);
Task<IPublishedContent?> GetByIdAsync(Guid key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public static IUmbracoBuilder AddUmbracoHybridCache(this IUmbracoBuilder builder
builder.AddNotificationAsyncHandler<MediaDeletedNotification, CacheRefreshingNotificationHandler>();
builder.AddNotificationAsyncHandler<ContentTypeRefreshedNotification, CacheRefreshingNotificationHandler>();
builder.AddNotificationAsyncHandler<ContentTypeDeletedNotification, CacheRefreshingNotificationHandler>();
builder.AddNotificationAsyncHandler<MediaTypeRefreshedNotification, CacheRefreshingNotificationHandler>();
builder.AddNotificationAsyncHandler<MediaTypeDeletedNotification, CacheRefreshingNotificationHandler>();
builder.AddNotificationAsyncHandler<UmbracoApplicationStartedNotification, SeedingNotificationHandler>();
builder.AddCacheSeeding();
return builder;
Expand Down
6 changes: 3 additions & 3 deletions src/Umbraco.PublishedCache.HybridCache/MediaCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public MediaCache(IMediaCacheService mediaCacheService, IPublishedContentTypeCac

public async Task<IPublishedContent?> GetByIdAsync(int id) => await _mediaCacheService.GetByIdAsync(id);

public async Task<IPublishedContent?> GetByKeyAsync(Guid key) => await _mediaCacheService.GetByKeyAsync(key);
public async Task<IPublishedContent?> GetByIdAsync(Guid key) => await _mediaCacheService.GetByKeyAsync(key);

public IPublishedContent? GetById(bool preview, int contentId) => GetByIdAsync(contentId).GetAwaiter().GetResult();

public IPublishedContent? GetById(bool preview, Guid contentId) =>
GetByKeyAsync(contentId).GetAwaiter().GetResult();
GetByIdAsync(contentId).GetAwaiter().GetResult();


public IPublishedContent? GetById(int contentId) => GetByIdAsync(contentId).GetAwaiter().GetResult();

public IPublishedContent? GetById(Guid contentId) => GetByKeyAsync(contentId).GetAwaiter().GetResult();
public IPublishedContent? GetById(Guid contentId) => GetByIdAsync(contentId).GetAwaiter().GetResult();


public IPublishedContentType? GetContentType(Guid key) => _publishedContentTypeCache.Get(PublishedItemType.Media, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ internal sealed class CacheRefreshingNotificationHandler :
INotificationAsyncHandler<MediaRefreshNotification>,
INotificationAsyncHandler<MediaDeletedNotification>,
INotificationAsyncHandler<ContentTypeRefreshedNotification>,
INotificationAsyncHandler<ContentTypeDeletedNotification>
INotificationAsyncHandler<ContentTypeDeletedNotification>,
INotificationAsyncHandler<MediaTypeRefreshedNotification>,
INotificationAsyncHandler<MediaTypeDeletedNotification>
{
private readonly IDocumentCacheService _documentCacheService;
private readonly IMediaCacheService _mediaCacheService;
Expand Down Expand Up @@ -126,7 +128,7 @@ public Task HandleAsync(ContentTypeRefreshedNotification notification, Cancellat
var contentTypeIds = notification.Changes.Where(x => x.ChangeTypes.HasTypesAny(types)).Select(x => x.Item.Id)
.ToArray();

if (contentTypeIds.Length != 0)
if (contentTypeIds.Length > 0)
{
foreach (var contentTypeId in contentTypeIds)
{
Expand All @@ -148,4 +150,33 @@ public Task HandleAsync(ContentTypeDeletedNotification notification, Cancellatio

return Task.CompletedTask;
}

public Task HandleAsync(MediaTypeRefreshedNotification notification, CancellationToken cancellationToken)
{
const ContentTypeChangeTypes types // only for those that have been refreshed
= ContentTypeChangeTypes.RefreshMain | ContentTypeChangeTypes.RefreshOther;
var mediaTypeIds = notification.Changes.Where(x => x.ChangeTypes.HasTypesAny(types)).Select(x => x.Item.Id)
.ToArray();

if (mediaTypeIds.Length > 0)
{
foreach (var mediaTypeId in mediaTypeIds)
{
_publishedContentTypeCache.ClearContentType(mediaTypeId);
}

_mediaCacheService.Rebuild(mediaTypeIds);
}
return Task.CompletedTask;
}

public Task HandleAsync(MediaTypeDeletedNotification notification, CancellationToken cancellationToken)
{
foreach (IMediaType deleted in notification.DeletedEntities )
{
_publishedContentTypeCache.ClearContentType(deleted.Id);
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ AND cmsContentNu.nodeId IS NULL
return CreateContentNodeKit(dto, serializer, preview);
}

private IEnumerable<ContentSourceDto> GetContentSourceByDocumentTypeKey(IEnumerable<Guid> documentTypeKeys)
private IEnumerable<ContentSourceDto> GetContentSourceByDocumentTypeKey(IEnumerable<Guid> documentTypeKeys, Guid objectType)
{
Guid[] keys = documentTypeKeys.ToArray();
if (keys.Any() is false)
Expand All @@ -248,19 +248,27 @@ private IEnumerable<ContentSourceDto> GetContentSourceByDocumentTypeKey(IEnumera
Sql<ISqlContext>? sql = SqlContentSourcesSelect()
.InnerJoin<NodeDto>("n")
.On<NodeDto, ContentDto>((n, c) => n.NodeId == c.ContentTypeId, "n", "umbracoContent")
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
.Append(SqlObjectTypeNotTrashed(SqlContext, objectType))
.WhereIn<NodeDto>(x => x.UniqueId, keys,"n")
.Append(SqlOrderByLevelIdSortOrder(SqlContext));

return GetContentNodeDtos(sql);
}

public IEnumerable<ContentCacheNode> GetContentByContentTypeKey(IEnumerable<Guid> keys)
public IEnumerable<ContentCacheNode> GetContentByContentTypeKey(IEnumerable<Guid> keys, ContentCacheDataSerializerEntityType entityType)
{
IEnumerable<ContentSourceDto> dtos = GetContentSourceByDocumentTypeKey(keys);
Guid objectType = entityType switch
{
ContentCacheDataSerializerEntityType.Document => Constants.ObjectTypes.Document,
ContentCacheDataSerializerEntityType.Media => Constants.ObjectTypes.Media,
ContentCacheDataSerializerEntityType.Member => Constants.ObjectTypes.Member,
_ => throw new ArgumentOutOfRangeException(nameof(entityType), entityType, null),
};

IEnumerable<ContentSourceDto> dtos = GetContentSourceByDocumentTypeKey(keys, objectType);

IContentCacheDataSerializer serializer =
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
_contentCacheDataSerializerFactory.Create(entityType);

foreach (ContentSourceDto row in dtos)
{
Expand All @@ -269,8 +277,8 @@ public IEnumerable<ContentCacheNode> GetContentByContentTypeKey(IEnumerable<Guid
}

/// <inheritdoc />
public IEnumerable<Guid> GetContentKeysByContentTypeKeys(IEnumerable<Guid> keys, bool published = false)
=> GetContentSourceByDocumentTypeKey(keys).Where(x => x.Published == published).Select(x => x.Key);
public IEnumerable<Guid> GetDocumentKeysByContentTypeKeys(IEnumerable<Guid> keys, bool published = false)
=> GetContentSourceByDocumentTypeKey(keys, Constants.ObjectTypes.Document).Where(x => x.Published == published).Select(x => x.Key);

public async Task<ContentCacheNode?> GetMediaSourceAsync(int id)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Infrastructure.HybridCache.Serialization;

namespace Umbraco.Cms.Infrastructure.HybridCache.Persistence;

Expand All @@ -15,14 +16,14 @@ internal interface IDatabaseCacheRepository
Task<ContentCacheNode?> GetMediaSourceAsync(Guid key);


IEnumerable<ContentCacheNode> GetContentByContentTypeKey(IEnumerable<Guid> keys);
IEnumerable<ContentCacheNode> GetContentByContentTypeKey(IEnumerable<Guid> keys, ContentCacheDataSerializerEntityType entityType);

/// <summary>
/// Gets all content keys of specific document types
/// </summary>
/// <param name="keys">The document types to find content using.</param>
/// <returns>The keys of all content use specific document types.</returns>
IEnumerable<Guid> GetContentKeysByContentTypeKeys(IEnumerable<Guid> keys, bool published = false);
IEnumerable<Guid> GetDocumentKeysByContentTypeKeys(IEnumerable<Guid> keys, bool published = false);

/// <summary>
/// Refreshes the nucache database row for the given cache node />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ContentTypeSeedKeyProvider(
public ISet<Guid> GetSeedKeys()
{
using ICoreScope scope = _scopeProvider.CreateCoreScope();
var documentKeys = _databaseCacheRepository.GetContentKeysByContentTypeKeys(_cacheSettings.ContentTypeKeys, published: true).ToHashSet();
var documentKeys = _databaseCacheRepository.GetDocumentKeysByContentTypeKeys(_cacheSettings.ContentTypeKeys, published: true).ToHashSet();
scope.Complete();

return documentKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Umbraco.Cms.Core.Services;
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 Down Expand Up @@ -97,7 +98,7 @@ public DocumentCacheService(
public IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
{
using ICoreScope scope = _scopeProvider.CreateCoreScope();
IEnumerable<ContentCacheNode> nodes = _databaseCacheRepository.GetContentByContentTypeKey([contentType.Key]);
IEnumerable<ContentCacheNode> nodes = _databaseCacheRepository.GetContentByContentTypeKey([contentType.Key], ContentCacheDataSerializerEntityType.Document);
scope.Complete();

return nodes
Expand Down Expand Up @@ -239,11 +240,11 @@ public async Task DeleteItemAsync(IContentBase content)
scope.Complete();
}

public void Rebuild(IReadOnlyCollection<int> contentTypeKeys)
public void Rebuild(IReadOnlyCollection<int> contentTypeIds)
{
using ICoreScope scope = _scopeProvider.CreateCoreScope();
_databaseCacheRepository.Rebuild(contentTypeKeys.ToList());
IEnumerable<ContentCacheNode> contentByContentTypeKey = _databaseCacheRepository.GetContentByContentTypeKey(contentTypeKeys.Select(x => _idKeyMap.GetKeyForId(x, UmbracoObjectTypes.DocumentType).Result));
_databaseCacheRepository.Rebuild(contentTypeIds.ToList());
IEnumerable<ContentCacheNode> contentByContentTypeKey = _databaseCacheRepository.GetContentByContentTypeKey(contentTypeIds.Select(x => _idKeyMap.GetKeyForId(x, UmbracoObjectTypes.DocumentType).Result), ContentCacheDataSerializerEntityType.Document);

foreach (ContentCacheNode content in contentByContentTypeKey)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IDocumentCacheService

Task DeleteItemAsync(IContentBase content);

void Rebuild(IReadOnlyCollection<int> contentTypeKeys);
void Rebuild(IReadOnlyCollection<int> contentTypeIds);

internal IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface IMediaCacheService
Task DeleteItemAsync(IContentBase media);

Task SeedAsync(CancellationToken cancellationToken);

void Rebuild(IReadOnlyCollection<int> contentTypeIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.HybridCache.Factories;
using Umbraco.Cms.Infrastructure.HybridCache.Persistence;
using Umbraco.Cms.Infrastructure.HybridCache.Serialization;

namespace Umbraco.Cms.Infrastructure.HybridCache.Services;

Expand Down Expand Up @@ -164,6 +165,26 @@ public async Task SeedAsync(CancellationToken cancellationToken)
scope.Complete();
}

public void Rebuild(IReadOnlyCollection<int> contentTypeIds)
{
using ICoreScope scope = _scopeProvider.CreateCoreScope();
_databaseCacheRepository.Rebuild(contentTypeIds.ToList());

IEnumerable<Guid> mediaTypeKeys = contentTypeIds.Select(x => _idKeyMap.GetKeyForId(x, UmbracoObjectTypes.MediaType))
.Where(x => x.Success)
.Select(x => x.Result);

IEnumerable<ContentCacheNode> mediaCacheNodesByContentTypeKey =
_databaseCacheRepository.GetContentByContentTypeKey(mediaTypeKeys, ContentCacheDataSerializerEntityType.Media);

foreach (ContentCacheNode media in mediaCacheNodesByContentTypeKey)
{
_hybridCache.RemoveAsync(GetCacheKey(media.Key, false));
}

scope.Complete();
}

private HybridCacheEntryOptions GetSeedEntryOptions() => new()
{
Expiration = _cacheSettings.SeedCacheDuration, LocalCacheExpiration = _cacheSettings.SeedCacheDuration,
Expand Down
75 changes: 75 additions & 0 deletions tests/Umbraco.Tests.Common/Builders/ContentEditingBaseBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Tests.Common.Builders.Interfaces;

namespace Umbraco.Cms.Tests.Common.Builders;

public abstract class ContentEditingBaseBuilder<TCreateModel> : BuilderBase<TCreateModel>,
IWithInvariantNameBuilder,
IWithKeyBuilder,
IWithContentTypeKeyBuilder,
IWithParentKeyBuilder,
IBuildContentTypes
where TCreateModel : ContentCreationModelBase, new()
{
protected TCreateModel _model = new();
private List<ContentEditingPropertyValueBuilder<ContentEditingBaseBuilder<TCreateModel>>> _invariantProperties = [];
private List<ContentEditingVariantBuilder<ContentEditingBaseBuilder<TCreateModel>>> _variants = [];
private Guid _contentTypeKey;
private Guid? _parentKey;
private Guid? _key;
private string _invariantName;

Guid? IWithKeyBuilder.Key
{
get => _key;
set => _key = value;
}

string IWithInvariantNameBuilder.InvariantName
{
get => _invariantName;
set => _invariantName = value;
}

Guid? IWithParentKeyBuilder.ParentKey
{
get => _parentKey;
set => _parentKey = value;
}

Guid IWithContentTypeKeyBuilder.ContentTypeKey
{
get => _contentTypeKey;
set => _contentTypeKey = value;
}

public ContentEditingPropertyValueBuilder<ContentEditingBaseBuilder<TCreateModel>> AddInvariantProperty()
{
var builder = new ContentEditingPropertyValueBuilder<ContentEditingBaseBuilder<TCreateModel>>(this);
_invariantProperties.Add(builder);
return builder;
}

public ContentEditingVariantBuilder<ContentEditingBaseBuilder<TCreateModel>> AddVariant()
{
var builder = new ContentEditingVariantBuilder<ContentEditingBaseBuilder<TCreateModel>>(this);
_variants.Add(builder);
return builder;
}

public override TCreateModel Build()
{
if (_parentKey is not null)
{
_model.ParentKey = _parentKey;
}

_model.InvariantName = _invariantName ?? Guid.NewGuid().ToString();
_model.ContentTypeKey = _contentTypeKey;
_model.Key = _key ?? Guid.NewGuid();
_model.InvariantProperties = _invariantProperties.Select(x => x.Build()).ToList();
_model.Variants = _variants.Select(x => x.Build()).ToList();

return _model;
}
}
Loading
Loading