-
Notifications
You must be signed in to change notification settings - Fork 813
V15: Cache seeding docs #6578
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: Cache seeding docs #6578
Changes from 5 commits
40ff469
0d8d3ce
ec8b569
fdc7bfa
da9ae70
d769841
ab35a91
6d45f44
206efbe
023b5e6
063c822
047d41a
12c0fc8
dcf8a9c
b4f315c
2886949
a4f6dc8
9c74b23
27bde31
3324029
c1148cd
fbf2b96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| --- | ||
| description: A guide to creating a custom seed key provider for Umbraco | ||
| --- | ||
|
|
||
| # Creating a Custom Seed Key Provider | ||
|
|
||
| From version 15 and onwards Umbraco uses a lazy loaded cache, this means content is loaded into the cache on an as-needed basis. | ||
| However, you may some specific content to always be in the cache, to achieve this you can implement your own custom seed key providers. | ||
|
|
||
| There is two types of seed key providers: `IDocumentSeedKeyProvider` for documents and `IMediaSeedKeyProvider` for media, | ||
| these interfaces are identical so only `IDocumentSeedKeyProvider` is demonstrated here. | ||
|
|
||
| {% hint style="warning" %} | ||
|
Check warning on line 13 in 15/umbraco-cms/extending/creating-custom-seed-key-provider.md
|
||
| Seed keys are themselves cached and only calculated once, this means that any documents created after the site has started won't be included in the seed keys untill ther server has restarted. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {% endhint %} | ||
|
|
||
| ## Implementation | ||
|
|
||
| This example implements a `IDocumentSeedKeyProvider` which seeds all the children of a node, in this case blog posts. | ||
|
|
||
| First we'll create a class called `BlogSeedKeyProvider` that implements `IDocumentSeedKeyProvider`. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```csharp | ||
| using Umbraco.Cms.Infrastructure.HybridCache; | ||
|
|
||
| namespace MySite.SeedKeyProviders; | ||
|
|
||
| public class BlogSeedKeyProvider : IDocumentSeedKeyProvider | ||
| { | ||
| public ISet<Guid> GetSeedKeys() | ||
| { | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Next we'll inject the `IDocumentNavigationQueryService` in order to get the children of the blog node. | ||
|
|
||
| ```csharp | ||
| using Umbraco.Cms.Core.Services.Navigation; | ||
| using Umbraco.Cms.Infrastructure.HybridCache; | ||
|
|
||
| namespace MySite.SeedKeyProviders; | ||
|
|
||
| public class BlogSeedKeyProvider : IDocumentSeedKeyProvider | ||
| { | ||
| private readonly IDocumentNavigationQueryService _documentNavigationQueryService; | ||
|
|
||
| public BlogSeedKeyProvider(IDocumentNavigationQueryService documentNavigationQueryService) | ||
| => _documentNavigationQueryService = documentNavigationQueryService; | ||
|
|
||
| {...} | ||
| ``` | ||
|
|
||
| Now we can parse a hardcoded string to a guid and use the `IDocumentNavigationQueryService` to get the children of the blog node and return their keys as a `HashSet`. | ||
|
Check warning on line 54 in 15/umbraco-cms/extending/creating-custom-seed-key-provider.md
|
||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```csharp | ||
| public ISet<Guid> GetSeedKeys() | ||
| { | ||
| var blogRoot = Guid.Parse("a5fdb22d-b7f2-4a59-8c4e-46ed86bde56c"); | ||
|
|
||
| if (_documentNavigationQueryService.TryGetChildrenKeys(blogRoot, out IEnumerable<Guid> blogPostKeys)) | ||
| { | ||
| return new HashSet<Guid>(blogPostKeys); | ||
| } | ||
|
|
||
| return new HashSet<Guid>(); | ||
| } | ||
| ``` | ||
| We since we're returning it as a set, and all the sets gets unioned, we don't have to worry about duplicates. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The final class looks like this: | ||
|
|
||
| ```csharp | ||
| using Umbraco.Cms.Core.Services.Navigation; | ||
| using Umbraco.Cms.Infrastructure.HybridCache; | ||
|
|
||
| namespace MySite.SeedKeyProviders; | ||
|
|
||
| public class BlogSeedKeyProvider : IDocumentSeedKeyProvider | ||
| { | ||
| private readonly IDocumentNavigationQueryService _documentNavigationQueryService; | ||
|
|
||
| public BlogSeedKeyProvider(IDocumentNavigationQueryService documentNavigationQueryService) | ||
| => _documentNavigationQueryService = documentNavigationQueryService; | ||
|
|
||
| public ISet<Guid> GetSeedKeys() | ||
| { | ||
| var blogRoot = Guid.Parse("a5fdb22d-b7f2-4a59-8c4e-46ed86bde56c"); | ||
|
|
||
| if (_documentNavigationQueryService.TryGetChildrenKeys(blogRoot, out IEnumerable<Guid> blogPostKeys)) | ||
| { | ||
| return new HashSet<Guid>(blogPostKeys); | ||
| } | ||
|
|
||
| return new HashSet<Guid>(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Registering the Seed Key Provider | ||
|
|
||
| Now that we have implemented the `BlogSeedKeyProvider` we need to register it in the `Startup` class. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```csharp | ||
| using MySite.SeedKeyProviders; | ||
| using Umbraco.Cms.Infrastructure.DependencyInjection; | ||
| using Umbraco.Cms.Infrastructure.HybridCache; | ||
|
|
||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.Services.AddSingleton<IDocumentSeedKeyProvider, BlogSeedKeyProvider>(); | ||
| {...} | ||
| ``` | ||
|
|
||
| Now all our blogpost will be seeded into the cache on startup, and will always be present in the cache. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- | ||
| description: Information about cache seeding | ||
| --- | ||
|
|
||
| # Cache Seeding | ||
|
|
||
| From version 15 and onwards Umbraco uses a lazy loaded cache, this means content is loaded into the cache on an as-needed basis | ||
|
Check warning on line 7 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
| that is whenever a piece of content is shown on the website for the first time it first needs to be loaded into the cache. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Loading the content into the cache causes a delay. This delay is dependent on the latency between your server and your database, but is generally minimal. | ||
| However, for certain pages, for instance the front page, you may not want this delay to be there, the role of cache seeding is to solve this issue. | ||
|
Check warning on line 11 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## How it works | ||
|
|
||
| Cache seeding is based upon the concept of a `ISeedKeyProvider`, the role of the seed key provider, is to specify what keys needs to be seeded. | ||
| There's two types of seed key providers, a `IDocumentSeedKeyProvider` which specifies which document should be seeded, and a `IMediaSeedKeyProvider` which specifies which media should be seeded. | ||
|
|
||
| During startup all the `ISeedKeyProviders` are run, and the keys they return are seeded into their respective caches, `IPublishedContentCache` for documents, and `IPublishedMediaCache` for media. | ||
| Additionally, whenever a document or media is then later changed, the cache will be updated with the changed content immediately, ensuring the content is always present in the cache. | ||
|
Check warning on line 19 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
| However, here it's important to note, that this means that whenever a piece of content is changed, Umbraco needs to go through the seeded keys to see if it's a piece of seeded content that was updated. | ||
|
Check warning on line 20 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
| Because of the need the check all seeded keys, Umbraco caches the keys themselves during startup. This means that if you have a dynamic seed key provider, any newly added content won't be considered seeded until the server restarts, | ||
|
Check warning on line 21 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
| for instance when seeding by Document Type any new content using the specified Document Type won't be seeded until a server restart. | ||
|
|
||
| ## Seed key providers | ||
|
|
||
| ### Default implementations | ||
|
|
||
| By default, Umbraco ships with two seed key providers for documents, and a single one for media. | ||
|
|
||
| For documents there is the `ContentTypeSeedKeyProvider` this seeds all documents of the given Document Types specified through app settings. | ||
|
|
||
| For both documents and media there is the `BreadthFirstKeyProvider` this provider does a breadth first traversal of the content and media tree respectively, seeding N number of content specified in the app settings. | ||
|
Check warning on line 32 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
|
|
||
| Configuration for the default seed key providers can be found in the [cache settings section.](../configuration/cache-settings.md) | ||
|
|
||
| ### Custom seed key providers | ||
|
|
||
| It's also possible to implement your own seed key providers, these are run alongside the default seed key providers on startup. | ||
| The returned keys are of all the seed key providers are unioned into a single set, this means that there will be no duplicates, so you don't need to worry consider this. | ||
|
Check warning on line 39 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
| However, as mentioned above the provided keys are cached, meaning that only the keys returned at startup will be considered seeded until the server restarts and the provider is run again. | ||
|
Check warning on line 40 in 15/umbraco-cms/reference/cache/cache-seeding.md
|
||
|
|
||
| For a specific example of how to implement a custom seed key provider, see [Creating a Custom Seed Key Provider](../extending/creating-custom-seed-key-provider.md). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| --- | ||
| description: Information on the Cache settings section | ||
| --- | ||
|
|
||
| # Cache settings | ||
|
|
||
| ## Seeding settings | ||
|
|
||
| The seeding settings allows you to specify which content should be seeded into your cache, for more information on cache seeding see [Cache Seeding.](../cache/cache-seeding.md) | ||
|
|
||
| ### ContentTypeKeys | ||
|
|
||
| The `ContentTypeKeys` setting is used to specify which document types should be seeded into the cache. The setting is a comma-separated list of document type keys. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "Cache": { | ||
| "ContentTypeKeys": ["e811405e-0190-4d3e-8387-7558521eec81", "419e89fb-8cff-4549-a074-9f8a30687828", "e0d71146-8205-4cf4-8236-f982b392259f"], | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### DocumentBreadthFirstSeedCount | ||
|
|
||
| The `DocumentBreadthFirstSeedCount` setting is used to specify how many documents should be seeded into the cache when doing a breadth first traversal, the default value is 100. | ||
|
|
||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "Cache": { | ||
| "DocumentBreadthFirstSeedCount": 500 | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## MediaBreadthFirstSeedCount | ||
|
|
||
| The `MediaBreadthFirstSeedCount` setting is used to specify how many media items should be seeded into the cache when doing a breadth first traversal, the default value is 100. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "Cache": { | ||
| "MediaBreadthFirstSeedCount": 500 | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Cache entry settings | ||
|
|
||
| The entry settings allows you to specify how long cache entries should be kept in the cache, the cache entry settings are identical for documents and media. | ||
|
|
||
| ## LocalCacheDuration | ||
|
|
||
| Specifies the duration that cache entries should be kept in the local memory cache, the default value is 24 hours. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "Cache": { | ||
| "Entry": { | ||
| "Document": { | ||
| "LocalCacheDuration": "2.00:00:00" | ||
| }, | ||
| "Media": { | ||
| "LocalCacheDuration": "50.00:00:00" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## RemoteCacheDuration | ||
|
|
||
| Specifies the duration that cache entries should be kept in the remote cache, second level cache, this setting is only relevant if second level cache is configured. The default value is 1 year. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "Cache": { | ||
| "Entry": { | ||
| "Document": { | ||
| "RemoteCacheDuration": "100.00:00:00" | ||
| }, | ||
| "Media": { | ||
| "RemoteCacheDuration": "150.00:00:00" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## SeedCacheDuration | ||
|
|
||
| Specifies the duration that seeded cache entries should be kept in the cache. The default value is 1 year. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "Cache": { | ||
| "Entry": { | ||
| "Document": { | ||
| "SeedCacheDuration": "200.00:00:00" | ||
| }, | ||
| "Media": { | ||
| "SeedCacheDuration": "250.00:00:00" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| # NuCache Settings | ||
|
|
||
| For backwards compatibility reasons, certain settings are still located under the `Umbraco:CMS:NuCache` settings node. | ||
|
|
||
| ## UsePagedSqlQuery | ||
|
|
||
| Setting `UsePagedSqlQuery` to `False` your project will use the `Fetch` method instead of the `QueryPaged` method when rebuilding the NuCache files. This will increase performance on bigger Umbraco websites with a lot of content when rebuilding the NuCache. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "NuCache": { | ||
| "UsePagedSqlQuery": false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ``` | ||
| ## SqlPageSize | ||
|
|
||
| Specifying the `SqlPageSize` will change the size of the paged sql queries, by default the value is 1000. | ||
|
|
||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "NuCache": { | ||
| "SqlPageSize": 500 | ||
| } | ||
| } | ||
| } | ||
| ``` |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.