Interface IMediaCacheService
Defines operations for the media cache service.
Namespace: Umbraco.Cms.Core.PublishedCache
Assembly: Umbraco.Core.dll
Syntax
public interface IMediaCacheService
Remarks
This service provides access to published media content with caching support, including operations for cache seeding, refreshing, and rebuilding.
Methods
View SourceClearConvertedContentCache()
Clears all converted IPublishedContent entries from the in-memory cache, without rebuilding the underlying database cache or HybridCache entries.
Declaration
void ClearConvertedContentCache()
Remarks
Use this when the published model factory is reset (e.g. InMemoryAuto mode), which invalidates all compiled model types and makes cached instances of any type stale.
ClearConvertedContentCache(IReadOnlyCollection<int>)
Clears converted IPublishedContent entries for the specified media types from the in-memory cache, without rebuilding the underlying database cache or HybridCache entries.
Declaration
void ClearConvertedContentCache(IReadOnlyCollection<int> mediaTypeIds)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyCollection<int> | mediaTypeIds | The IDs of the media types whose converted entries should be cleared. |
Remarks
Use this when the published model factory is NOT reset (e.g. SourceCodeAuto/SourceCodeManual modes), so only the affected media types need their converted cache cleared.
ClearMemoryCacheAsync(CancellationToken)
Clears all entries from the memory cache.
Declaration
Task ClearMemoryCacheAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token to observe while waiting for the task to complete. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
DeleteItemAsync(IContentBase)
Removes the specified media item from the cache.
Declaration
Task DeleteItemAsync(IContentBase media)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | media | The media item to remove from the cache. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
GetByContentType(IPublishedContentType)
Gets all published media items of the specified content type.
Declaration
IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| IPublishedContentType | contentType | The published content type to filter by. |
Returns
| Type | Description |
|---|---|
| IEnumerable<IPublishedContent> | A collection of published media items of the specified type. |
GetByIdAsync(int)
Gets a published media item by its integer identifier.
Declaration
Task<IPublishedContent?> GetByIdAsync(int id)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | The integer identifier of the media. |
Returns
| Type | Description |
|---|---|
| Task<IPublishedContent> | The published media content, or |
GetByKeyAsync(Guid)
Gets a published media item by its unique key.
Declaration
Task<IPublishedContent?> GetByKeyAsync(Guid key)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique key of the media. |
Returns
| Type | Description |
|---|---|
| Task<IPublishedContent> | The published media content, or |
HasContentByIdAsync(int)
Determines whether media with the specified identifier exists in the cache.
Declaration
Task<bool> HasContentByIdAsync(int id)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | The integer identifier of the media. |
Returns
| Type | Description |
|---|---|
| Task<bool> |
|
Rebuild(IReadOnlyCollection<int>)
Rebuilds the cache for media items of the specified media types.
Declaration
void Rebuild(IReadOnlyCollection<int> contentTypeIds)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyCollection<int> | contentTypeIds | The collection of media type identifiers to rebuild. |
RebuildMemoryCacheByContentTypeAsync(IEnumerable<int>)
Rebuilds the memory cache for media items of the specified media types.
Declaration
Task RebuildMemoryCacheByContentTypeAsync(IEnumerable<int> mediaTypeIds)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<int> | mediaTypeIds | The collection of media type identifiers to rebuild in memory cache. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
RefreshMediaAsync(IMedia)
Refreshes the cache entry for the specified media item.
Declaration
Task RefreshMediaAsync(IMedia media)
Parameters
| Type | Name | Description |
|---|---|---|
| IMedia | media | The media item to refresh in the cache. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
RefreshMemoryCacheAsync(Guid)
Refreshes the memory cache entry for the media item with the specified key.
Declaration
Task RefreshMemoryCacheAsync(Guid key)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique key of the media to refresh. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
RemoveFromMemoryCacheAsync(Guid)
Removes the media item with the specified key from the memory cache.
Declaration
Task RemoveFromMemoryCacheAsync(Guid key)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | key | The unique key of the media to remove. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
SeedAsync(CancellationToken)
Seeds the cache with initial media data.
Declaration
Task SeedAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token to observe while waiting for the task to complete. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |