|
| 1 | +--- |
| 2 | +description: Information about cache seeding |
| 3 | +--- |
| 4 | + |
| 5 | +# Cache Seeding |
| 6 | + |
| 7 | +From version 15 and onwards Umbraco uses a lazy loaded cache, this means content is loaded into the cache on an as-needed basis |
| 8 | +I.E. whenever a piece of content is shown on the website for the first time it first needs to be loaded into the cache. |
| 9 | + |
| 10 | +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. |
| 11 | +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. |
| 12 | + |
| 13 | +## How it works |
| 14 | + |
| 15 | +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. |
| 16 | +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. |
| 17 | + |
| 18 | +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. |
| 19 | +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 case. |
| 20 | +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. |
| 21 | +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, |
| 22 | +for instance when seeding by document type any new content using the specified document type won't be seeded until a server restart. |
| 23 | + |
| 24 | +## Seed key providers |
| 25 | + |
| 26 | +### Default implementations. |
| 27 | + |
| 28 | +By default, umbraco ships with two seed key providers for documents, and a single one for media. |
| 29 | + |
| 30 | +For documents there is the `ContentTypeSeedKeyProvider` this seeds all documents of the given document types specified through app settings. |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +Configuration for the default seed key providers can be found in the [cache settings section.](../configuration/cache-settings.md) |
| 35 | + |
| 36 | +### Custom seed key providers |
| 37 | + |
| 38 | +It's also possible to implement your own seed key providers, these are run alongside the default seed key providers on startup. |
| 39 | +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. |
| 40 | +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. |
| 41 | + |
| 42 | +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). |
0 commit comments