Class SingleServerCacheVersionService
A simple cache version service that assumes the cache is always in sync.
Inheritance
Namespace: Umbraco.Cms.Core.Cache
Assembly: Umbraco.Core.dll
Syntax
public class SingleServerCacheVersionService : IRepositoryCacheVersionService
Constructors
View SourceSingleServerCacheVersionService()
Declaration
public SingleServerCacheVersionService()
Methods
View SourceFlushCacheUpdatesAsync()
Publishes the cache updates registered by SetCacheUpdatedAsync<TEntity>() whose publication was deferred.
Declaration
public Task FlushCacheUpdatesAsync()
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Called once the cache instructions for the current unit of work have been written. Implementations that publish updates immediately have nothing to do here.
GetCacheVersionsAsync()
Gets the cache versions currently published for all entity types.
Declaration
public Task<IReadOnlyCollection<RepositoryCacheVersion>> GetCacheVersionsAsync()
Returns
| Type | Description |
|---|---|
| Task<IReadOnlyCollection<RepositoryCacheVersion>> | The published cache versions; a version whose value is null has never been published. |
Remarks
The synchronization reads this snapshot before processing the cache instructions and adopts it afterwards through SetCachesSyncedAsync(IEnumerable<RepositoryCacheVersion>), so the two must be implemented together. No snapshot can be derived from the other members, so the default implementation throws.
Exceptions
| Type | Condition |
|---|---|
| NotImplementedException | Thrown when the implementation does not provide the snapshot. |
IsCacheSyncedAsync<TEntity>()
Validates if the cache is synced with the database.
Declaration
public Task<bool> IsCacheSyncedAsync<TEntity>() where TEntity : class
Returns
| Type | Description |
|---|---|
| Task<bool> | True if cache is synced, false if cache needs fast-forwarding. |
Type Parameters
| Name | Description |
|---|---|
| TEntity | The type of the cached entity. |
SetCacheUpdatedAsync<TEntity>()
Registers a cache update for the specified entity type.
Declaration
public Task SetCacheUpdatedAsync<TEntity>() where TEntity : class
Returns
| Type | Description |
|---|---|
| Task |
Type Parameters
| Name | Description |
|---|---|
| TEntity | The type of the cached entity. |
Remarks
Other servers detect the update through the published cache version. An implementation may defer publishing it until FlushCacheUpdatesAsync() is called, so that the version never becomes visible before the cache instructions that describe the change.
SetCachesSyncedAsync()
Registers that the cache has been synced with the database.
Declaration
public Task SetCachesSyncedAsync()
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Adopts the versions currently published. Prefer SetCachesSyncedAsync(IEnumerable<RepositoryCacheVersion>) with versions read before the cache instructions were processed.
SetCachesSyncedAsync(IEnumerable<RepositoryCacheVersion>)
Registers that the local caches have been synced up to the given cache versions.
Declaration
public Task SetCachesSyncedAsync(IEnumerable<RepositoryCacheVersion> cacheVersions)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<RepositoryCacheVersion> | cacheVersions | The versions read before the cache instructions were processed, typically from GetCacheVersionsAsync(). |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Adopting the versions read before processing, rather than the versions published afterwards, means a version published while instructions were being processed is still seen as out of date and triggers another sync. Concurrent syncs may adopt an older set last; that costs one redundant sync and nothing more. Delegating to SetCachesSyncedAsync() would discard the snapshot and reintroduce that race, so the default implementation throws instead.
Exceptions
| Type | Condition |
|---|---|
| NotImplementedException | Thrown when the implementation does not adopt the given snapshot. |