Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
40ff469
Add custom seed provider documentation
nikolajlauridsen Oct 21, 2024
0d8d3ce
Remove unnecessary using
nikolajlauridsen Oct 21, 2024
ec8b569
Add general cache seeding and configuration information
nikolajlauridsen Oct 22, 2024
fdc7bfa
Minor fixes
nikolajlauridsen Oct 22, 2024
da9ae70
Few more fixes
nikolajlauridsen Oct 22, 2024
d769841
Fixed long sentences
sofietoft Oct 24, 2024
ab35a91
Fixed long sentences
sofietoft Oct 24, 2024
6d45f44
Apply suggestions from code review
nikolajlauridsen Oct 28, 2024
206efbe
Update SUMMARY.md
sofietoft Oct 30, 2024
023b5e6
Update .gitbook.yaml
sofietoft Oct 30, 2024
063c822
Update release-candidate-guide.md
sofietoft Oct 30, 2024
047d41a
Merge branch 'main' into v15/cache-docs
sofietoft Oct 30, 2024
12c0fc8
Added note about missing NuCache Settings article
sofietoft Oct 31, 2024
dcf8a9c
Add HybridCacheOptions section
nikolajlauridsen Oct 31, 2024
b4f315c
Tiny corrections to appease GitBook
sofietoft Oct 31, 2024
2886949
Merge branch 'main' into v15/add-maximumpayload-bytes-settings
nikolajlauridsen Oct 31, 2024
a4f6dc8
Merge branch 'main' into v15/cache-docs
nikolajlauridsen Oct 31, 2024
9c74b23
Merge branch 'v15/cache-docs' into v15/add-maximumpayload-bytes-settings
nikolajlauridsen Oct 31, 2024
27bde31
Merge pull request #1 from nikolajlauridsen/v15/add-maximumpayload-by…
nikolajlauridsen Nov 5, 2024
3324029
Update 15/umbraco-cms/reference/configuration/cache-settings.md
nikolajlauridsen Nov 6, 2024
c1148cd
Minor change to trigger GitBook checks
sofietoft Nov 6, 2024
fbf2b96
GitBook checks
sofietoft Nov 6, 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
115 changes: 115 additions & 0 deletions 15/umbraco-cms/extending/creating-custom-seed-key-provider.md
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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "15/umbraco-cms/extending/creating-custom-seed-key-provider.md", "range": {"start": {"line": 13, "column": 4}}}, "severity": "WARNING"}
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.
{% 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`.

```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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "15/umbraco-cms/extending/creating-custom-seed-key-provider.md", "range": {"start": {"line": 54, "column": 1}}}, "severity": "WARNING"}

```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.

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.

```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.
43 changes: 43 additions & 0 deletions 15/umbraco-cms/reference/cache/cache-seeding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "15/umbraco-cms/reference/cache/cache-seeding.md", "range": {"start": {"line": 7, "column": 1}}}, "severity": "WARNING"}
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.

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

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). Raw Output: {"message": "[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words).", "location": {"path": "15/umbraco-cms/reference/cache/cache-seeding.md", "range": {"start": {"line": 11, "column": 1}}}, "severity": "WARNING"}

## How it works

Cache seeding is based on the concept of an `ISeedKeyProvider`. The role of the seed key provider is to specify what keys need to be seeded.

There are two types of seed key providers: an `IDocumentSeedKeyProvider` specifying which document should be seeded, and an `IMediaSeedKeyProvider` specifying 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 changed, the cache will immediately be updated with the changed content. This ensures that the content is always present in the cache.

Whenever a piece of content is changed, the seeded keys must be checked, to see if the updated content was seeded. 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 will not be considered seeded until the server restarts. For instance, when seeding by Document Type any new content using the specified Document Type will not be seeded until the server is restarted.

## Seed key providers

### Default implementations

By default, Umbraco ships with two seed key providers for documents, and one for media.

For documents, the `ContentTypeSeedKeyProvider` seeds all documents of the given Document Types specified in the `appSettings.json` file.

For documents and media, the `BreadthFirstKeyProvider` does a breadth-first traversal of the content and media tree respectively. This will seed N number of content specified in the `appSettings.json` file.

The default seed key provider configuration can be found in the [cache settings section.](../configuration/cache-settings.md).

### Custom seed key providers

It is also possible to implement custom seed key providers. These are run alongside the default seed key providers on startup.

The returned keys of all the seed key providers are unioned into a single set. This means there will be no duplicates.

As mentioned above the provided keys are cached. Only the keys returned at startup will be considered seeded until the server restarts and the provider is rerun.

For a specific example of implementing a custom seed key provider, see [Creating a Custom Seed Key Provider](../extending/creating-custom-seed-key-provider.md).
150 changes: 150 additions & 0 deletions 15/umbraco-cms/reference/configuration/cache-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
description: Information on the Cache settings section
---

# Cache settings

## Seeding settings

The Seeding settings allow you to specify which content should be seeded into your cache. For more information on cache seeding see the [Cache Seeding.](../cache/cache-seeding.md) article.

### ContentTypeKeys

The `ContentTypeKeys` setting specifies 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 specifies 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 specifies 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 allow you to specify how long cache entries should be kept. 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 a 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 for which 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 backward compatibility reasons, certain settings are 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. The default value is 1000.

```json
"Umbraco": {
"CMS": {
"NuCache": {
"SqlPageSize": 500
}
}
}
```
56 changes: 0 additions & 56 deletions 15/umbraco-cms/reference/configuration/nucachesettings.md

This file was deleted.

Loading