Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache
Paul Johnson 01d2d0326c Merge release/10.0.0 into v10/dev
commit e0aa430d4c
Author: Paul Johnson <pmj@umbraco.com>
Date:   Thu May 19 10:00:57 2022 +0100

    Fix typo in pipeline yaml

commit 2ec450f2d6
Author: Paul Johnson <pmj@umbraco.com>
Date:   Thu May 19 09:14:47 2022 +0100

    Fix yaml conditions

commit c2d548039a
Author: Paul Johnson <pmj@umbraco.com>
Date:   Thu May 19 09:02:50 2022 +0100

    Azure pipeline refactor (#12428)

    * Skip symbols for Umbraco.Templates

    * Resolve some test issues

    + Fixed whitespace dependant tests to pass regardless of build OS vs
    run OS.

    + Snap dictionary tests were failing when Configuration was release

    + Removed hardcoded baseUrl from one of the acceptance tests

    * Move docfx setup to ./build and fix

    * Update UI docs title

    * Added dockerfile that can be used when running the acceptance tests.

    * Take explicit dependency on System.Security.Cryptography.Pkcs

    * Refactor ci/cd pipeline

commit ee8359af75
Author: Mole <nikolajlauridsen@protonmail.ch>
Date:   Thu May 19 09:57:21 2022 +0200

    V10: Reintroduce appsettings-schema.json (#12416)

    * Reintroduce language files tests (#12367)

    * Reintroducing language files tests

    * Fix casing

    * Update tests/Umbraco.Tests.UnitTests/Umbraco.Core/EmbeddedResources/LanguageXmlTests.cs

    Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

    * Change Umbraco.Cms and Umbraco.Templates nuspecs to csproj

    * Remove Umbraco.Templates from VerifyNuGet step

    * Remove duplicate and unnecessary properties

    * Generate json schema on build

    * Add targets file

    * Gitignore auto generated appsettings schema

    * Fix build not copying file

    * Use the new path in appsettings

    * Update copy message

    * Build json schema as release

    * Update json schema options

    Otherwise just running the project will put the file in the wrong place

    * Generate schema if it doesn't exist in Web.Ui

    * Update json schema options

    Otherwise just running the project will put the file in the wrong place

    Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
    Co-authored-by: Ronald Barendse <ronald@barend.se>

commit dd617ede80
Author: Ronald Barendse <ronald@barend.se>
Date:   Thu May 19 09:51:11 2022 +0200

    v10: Change Umbraco.Cms and Umbraco.Templates nuspecs to csproj (#12413)

    * Reintroduce language files tests (#12367)

    * Reintroducing language files tests

    * Fix casing

    * Update tests/Umbraco.Tests.UnitTests/Umbraco.Core/EmbeddedResources/LanguageXmlTests.cs

    Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

    * Change Umbraco.Cms and Umbraco.Templates nuspecs to csproj

    * Remove Umbraco.Templates from VerifyNuGet step

    * Remove duplicate and unnecessary properties

    Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
    Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

commit b83216876f
Author: Ronald Barendse <ronald@barend.se>
Date:   Thu May 19 08:36:04 2022 +0200

    v10: Project template database/connection string improvements (#12407)

    * Add new connection-string-provider-name parameter

    * Use template value forms to correctly encode JSON values

    * Add new development-database-type parameter

    * Update package template and fix App_Plugins directory rename

    * Remove conflicting short parameter name

    * Lowercase framework parameter to align with MS templates

    * Cleanup default template settings

    * Write unattended install parameters when either connection string or development database is set

    * Include RootNamespace in UmbracoPackage template

    * Update Umbraco specific gitignore rules

    * Revert "Lowercase framework parameter to align with MS templates"

    This reverts commit 22de389272a7e119df569ec2e54190265f6d0ae0.

    * Add exclude-gitignore parameter

    * Update template schemas

    * Add minimal-gitignore parameter

commit e40049dcf1
Author: Mole <nikolajlauridsen@protonmail.ch>
Date:   Wed May 18 15:22:51 2022 +0200

    Fix domain for invariant content nodes (#12405)

    Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>

commit a3692b887a
Author: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
Date:   Mon May 9 11:42:10 2022 +0200

    Use SnippetCollection to when working with snippets  (#12355)

    * Introducing a new Snippet type

    * Adding a SnippetCollection and SnippetCollectionBuilder

    * Using snippetCollection to get the snippets instead of fileService

    * Fixed fetching the correct content

    * Make ISnippet non-discoverable

    * Split the SnippetCollection into PartialViewSnippetCollection and PartialViewMacroSnippetCollection

    * Update CodeFileController to use the 2 snippet collections

    * Display the names with Empty.cshtml on top

    * Remove merging embedded snippets with custom snippets from ~\Umbraco.Web.UI\umbraco\PartialViewMacros\Templates folder for the Partial View Collection

    * Fix naming

    * Fix another naming

    * Cleanup + Use base items

    Co-authored-by: Bjarke Berg <mail@bergmania.dk>
    (cherry picked from commit 9326cc5fc6)

commit 4f48a4937b
Author: patrickdemooij9 <patrickdemooij98@hotmail.com>
Date:   Fri Oct 8 11:18:00 2021 +0200

    Cherry picked from 4c08b44684

commit 4fdbfee597
Author: Bjarne Fyrstenborg <bjarne_fyrstenborg@hotmail.com>
Date:   Wed May 11 00:51:37 2022 +0200

    Show nicer overlay when clicking block card for deleted element type (#12140)

    * Show nicer overlay when clicking block card for deleted element type

    * Cleanup

    * Remove stop-scrolling container

    * Use flex-start instead on start

    * Remove legacy flexbox fallback

    * Remove unnecessary hack

    * Use standard gap property instead

    * Localization of message

    * Fix translation

    * End sentence with a dot

    (cherry picked from commit ebb1dc21a9)

commit 3856bf8288
Author: Henk Jan Pluim <henkjan.pluim@greenchoice.nl>
Date:   Mon Apr 25 10:02:06 2022 +0200

    #fix 12254 return emptyresult

    (cherry picked from commit 7993d19c1b)

commit 7087c3d9f6
Author: Ronald Barendse <ronald@barend.se>
Date:   Tue May 17 12:59:01 2022 +0200

    v10: Use ForceCreateDatabase during unattended install and extend GetUmbracoConnectionString extension methods (#12397)

    * Add extension methods to get the Umbraco connection string/provider name from configuration

    * Added tests for configuration extension methods.

    * Fix issue with InstallMissingDatabase and ForceCreateDatabase

    * Fix comments

    * Revert casing change in GenerateConnectionString

    * Re-add AddOptions (without config binding) to fix test

    * Update src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs

    Co-authored-by: Ronald Barendse <ronald@barend.se>

    * Update src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs

    * Update src/Umbraco.Infrastructure/Runtime/RuntimeState.cs

    * Whitespace and documentation updates

    * Add DatabaseProviderMetadataExtensions

    * Filter before ordering

    * Replace DataDirectory placeholder when setting connection string

    Co-authored-by: Andy Butland <abutland73@gmail.com>
    Co-authored-by: Bjarke Berg <mail@bergmania.dk>
    (cherry picked from commit 8e6e262c7f)

commit e90bf26577
Author: Ronald Barendse <ronald@barend.se>
Date:   Tue May 17 07:33:54 2022 +0200

    v10: Support System.Data.SqlClient provider name (#12408)

    * Add support for System.Data.SqlClient provider name

    * Only update connection string when required

    (cherry picked from commit e82bcb1b76)

commit fd0637c96d
Author: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
Date:   Mon May 16 14:23:59 2022 +0200

    Reintroduce language files tests (#12367)

    * Reintroducing language files tests

    * Fix casing

    * Update tests/Umbraco.Tests.UnitTests/Umbraco.Core/EmbeddedResources/LanguageXmlTests.cs

    Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
    (cherry picked from commit 2ed71a64ec)
2022-05-19 10:25:44 +01:00
..

NuCache Documentation

HOW IT WORKS

NuCache uses a ContentStore to keep content - basically, a dictionary of int => content, and some logic to maintain it up-to-date. In order to provide immutable content to pages rendering, a ContentStore can create ContentViews. A ContentView basically is another int => content dictionary, containing entries only for things that have changed in the ContentStore - so the ContentStore changes, but it updates the views so that they

Views are chained, ie each new view is the parent of previously existing views. A view knows its parent but not the other way round, so views just disappear when they are GC.

When reading the cache, we read views up the chain until we find a value (which may be null) for the given id, and finally we read the store itself.

The PublishedSnapshotService manages a ContentStore for content, and another for media. When a PublishedSnapshot is created, the PublishedSnapshotService gets ContentView objects from the stores. Views provide an immutable snapshot of the content and media.

When the PublishedSnapshotService is notified of changes, it notifies the stores. Then it resync the current PublishedSnapshot, so that it requires new views, etc.

Whenever a content, media or member is modified or removed, the cmsContentNu table is updated with a json dictionary of alias => property value, so that a content, media or member can be loaded with one database row - this is what is used to populate the in-memory cache.

A ContentStore actually stores ContentNode instances, which contain what's common to both the published and draft version of content + the actual published and/or draft content.

LOCKS

Each ContentStore is protected by a reader/writer lock 'Locker' that is used both by the store and its views to ensure that the store remains consistent.

Each ContentStore has a _freezeLock object used to protect the 'Frozen' state of the store. It's a disposable object that releases the lock when disposed, so usage would be: using (store.Frozen) { ... }.

The PublishedSnapshotService has a _storesLock object used to guarantee atomic access to the set of content, media stores.

CACHE

For each set of views, the PublishedSnapshotService creates a SnapshotCache. So a SnapshotCache is valid until anything changes in the content or media trees. In other words, things that go in the SnapshotCache stay until a content or media is modified.

For each PublishedSnapshot, the PublishedSnapshotService creates a PublishedSnapshotCache. So a PublishedSnapshotCache is valid for the duration of the PublishedSnapshot (usually, the request). In other words, things that go in the PublishedSnapshotCache stay (and are visible to) for the duration of the request only.

The PublishedSnapshotService defines a static constant FullCacheWhenPreviewing, that defines how caches operate when previewing:

  • when true, the caches in preview mode work normally.
  • when false, everything that would go to the SnapshotCache goes to the PublishedSnapshotCache. At the moment it is true in the code, which means that eg converted values for previewed content will go in the SnapshotCache. Makes for faster preview, but uses more memory on the long term... would need some benchmarking to figure out what is best.

Members only live for the duration of the PublishedSnapshot. So, for members SnapshotCache is never used, and everything goes to the PublishedSnapshotCache.

All cache keys are computed in the CacheKeys static class.

TESTS

For testing purposes the following mechanisms exist:

The PublishedSnapshot type has a static Current property that is used to obtain the 'current' PublishedSnapshot in many places, going through the PublishedCachesServiceResolver to get the current service, and asking the current service for the current PublishedSnapshot, which by default relies on UmbracoContext. For test purposes, it is possible to override the entire mechanism by defining PublishedSnapshot.GetCurrentPublishedSnapshotFunc which should return a PublishedSnapshot.

A PublishedContent keeps only id-references to its parent and children, and needs a way to retrieve the actual objects from the cache - which depends on the current PublishedSnapshot. It is possible to override the entire mechanism by defining PublishedContent. GetContentByIdFunc or .GetMediaByIdFunc.

Setting these functions must be done before Resolution is frozen.

STATUS

"Detached" contents & properties, which need to be refactored anyway, are not supported by NuCache - throwing NotImplemented in ContentCache.

All the cached elements rely on guids for the cache key, and not ints, so it could be possible to support detached contents & properties, even those that do not have an actual int id, but again this should be refactored entirely anyway.

Not doing any row-version checks (see XmlStore) when reloading from database, though it is maintained in the database. Two FIXME in PublishedSnapshotService. Should we do it?

There is no on-disk cache at all so everything is reloaded from the cmsContentNu table when the site restarts. This is pretty fast, but we should experiment with solutions to store things locally (and deal with the sync issues, see XmlStore...).

Doing our best with PublishedMember but the whole thing should be refactored, because PublishedMember exposes properties that IPublishedContent does not, and that are going to be lost soon as the member is wrapped (content set, model...) - so we probably need some sort of IPublishedMember.

/