Interface IElementCacheService
Defines operations for the element cache service.
Namespace: Umbraco.Cms.Core.PublishedCache
Assembly: Umbraco.Core.dll
Syntax
public interface IElementCacheService : IContentCacheService
Remarks
This service provides access to published element content with caching support, including operations for cache refreshing and rebuilding.
Methods
View SourceGetByContentType(IPublishedContentType)
Gets all published elements of the specified content type.
Declaration
IEnumerable<IPublishedElement> GetByContentType(IPublishedContentType contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| IPublishedContentType | contentType | The published content type to filter by. |
Returns
| Type | Description |
|---|---|
| IEnumerable<IPublishedElement> | A collection of published elements of the specified type. |
GetByKeyAsync(Guid, bool?)
Gets a published element by its unique key.
Declaration
Task<IPublishedElement?> GetByKeyAsync(Guid key, bool? preview = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique key of the element. |
| bool? | preview | Optional value indicating whether to include unpublished content. If |
Returns
| Type | Description |
|---|---|
| Task<IPublishedElement> | The published element, or |
RefreshElementAsync(IElement)
Refreshes the cache entry for the specified element.
Declaration
Task RefreshElementAsync(IElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| IElement | element | The element to refresh in the cache. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
TryGetCached(Guid, bool, out IPublishedElement?)
Attempts to retrieve an element from the in-memory converted-content cache without touching the distributed cache or the database.
Declaration
bool TryGetCached(Guid key, bool preview, out IPublishedElement? element)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique key of the element. |
| bool | preview | Whether to consider unpublished content. |
| IPublishedElement | element | When this method returns, contains the cached published element if a hit was made; otherwise |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Synchronous fast-path used by sync consumers (e.g. IPublishedElementCache.GetById(bool, Guid)
and property value converters that sync-over-async) to avoid setting up the async state
machine on the dominant warm-cache case. On a miss the caller falls back to the existing
async path. The default implementation always returns false so the caller takes the
async path.