Class DefaultRepositoryCachePolicy<TEntity, TId>
Represents the default cache policy.
Namespace: Umbraco.Cms.Core.Cache
Assembly: Umbraco.Infrastructure.dll
Syntax
public class DefaultRepositoryCachePolicy<TEntity, TId> : RepositoryCachePolicyBase<TEntity, TId>, IRepositoryCachePolicy<TEntity, TId> where TEntity : class, IEntity
Type Parameters
| Name | Description |
|---|---|
| TEntity | The type of the entity. |
| TId | The type of the identifier. |
Remarks
The default cache policy caches entities with a sliding expiration (see Umbraco.Cms.Core.Cache.RepositoryCacheConstants.DefaultCacheDuration).
Each entity is cached individually.
If options.GetAllCacheAllowZeroCount then a 'zero-count' array is cached when GetAll finds nothing.
If options.GetAllCacheValidateCount then we check against the db when getting many entities.
Constructors
View SourceDefaultRepositoryCachePolicy(IAppPolicyCache, IScopeAccessor, RepositoryCachePolicyOptions)
Initializes a new instance of the DefaultRepositoryCachePolicy<TEntity, TId> class, which manages caching for repository entities.
Declaration
[Obsolete("Please use the constructor with all parameters. Scheduled for removal in Umbraco 18.")]
public DefaultRepositoryCachePolicy(IAppPolicyCache cache, IScopeAccessor scopeAccessor, RepositoryCachePolicyOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| IAppPolicyCache | cache | The application-level policy cache used for storing cached items. |
| IScopeAccessor | scopeAccessor | Provides access to the current scope for cache operations. |
| RepositoryCachePolicyOptions | options | The configuration options for the repository cache policy. |
DefaultRepositoryCachePolicy(IAppPolicyCache, IScopeAccessor, RepositoryCachePolicyOptions, IRepositoryCacheVersionService, ICacheSyncService)
Initializes a new instance of the DefaultRepositoryCachePolicy<TEntity, TId> class.
Declaration
public DefaultRepositoryCachePolicy(IAppPolicyCache cache, IScopeAccessor scopeAccessor, RepositoryCachePolicyOptions options, IRepositoryCacheVersionService repositoryCacheVersionService, ICacheSyncService cacheSyncService)
Parameters
| Type | Name | Description |
|---|---|---|
| IAppPolicyCache | cache | The application-level policy cache used for storing repository items. |
| IScopeAccessor | scopeAccessor | Provides access to the current scope. |
| RepositoryCachePolicyOptions | options | The options that configure repository cache policy behavior. |
| IRepositoryCacheVersionService | repositoryCacheVersionService | Service for managing repository cache versions. |
| ICacheSyncService | cacheSyncService | Service responsible for synchronizing cache across instances. |
Properties
View SourceEntityTypeCacheKey
Declaration
protected string EntityTypeCacheKey { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
View SourceClearAll()
Clears the entire cache.
Declaration
public override void ClearAll()
Create(TEntity, Action<TEntity>)
Creates an entity.
Declaration
public override void Create(TEntity entity, Action<TEntity> persistNew)
Parameters
| Type | Name | Description |
|---|---|---|
| TEntity | entity | The entity. |
| Action<TEntity> | persistNew | The repository PersistNewItem method. |
Remarks
Creates the entity in the repository, and updates the cache accordingly.
Delete(TEntity, Action<TEntity>)
Removes an entity.
Declaration
public override void Delete(TEntity entity, Action<TEntity> persistDeleted)
Parameters
| Type | Name | Description |
|---|---|---|
| TEntity | entity | The entity. |
| Action<TEntity> | persistDeleted | The repository PersistDeletedItem method. |
Remarks
Removes the entity from the repository and clears the cache.
Exists(TId, Func<TId, bool>, Func<TId[], IEnumerable<TEntity>?>)
Gets a value indicating whether an entity with a specified identifier exists.
Declaration
public override bool Exists(TId id, Func<TId, bool> performExists, Func<TId[], IEnumerable<TEntity>?> performGetAll)
Parameters
| Type | Name | Description |
|---|---|---|
| TId | id | The identifier. |
| Func<TId, bool> | performExists | The repository PerformExists method. |
| Func<TId[], IEnumerable<TEntity>> | performGetAll | The repository PerformGetAll method. |
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether an entity with the specified identifier exists. |
Remarks
First considers the cache then the repository.
Get(TId?, Func<TId?, TEntity?>, Func<TId[]?, IEnumerable<TEntity>?>)
Gets an entity from the cache, else from the repository.
Declaration
public override TEntity? Get(TId? id, Func<TId?, TEntity?> performGet, Func<TId[]?, IEnumerable<TEntity>?> performGetAll)
Parameters
| Type | Name | Description |
|---|---|---|
| TId | id | The identifier. |
| Func<TId, TEntity> | performGet | The repository PerformGet method. |
| Func<TId[], IEnumerable<TEntity>> | performGetAll | The repository PerformGetAll method. |
Returns
| Type | Description |
|---|---|
| TEntity | The entity with the specified identifier, if it exits, else null. |
Remarks
First considers the cache then the repository.
GetAll(TId[]?, Func<TId[]?, IEnumerable<TEntity>?>)
Gets entities.
Declaration
public override TEntity[] GetAll(TId[]? ids, Func<TId[]?, IEnumerable<TEntity>?> performGetAll)
Parameters
| Type | Name | Description |
|---|---|---|
| TId[] | ids | The identifiers. |
| Func<TId[], IEnumerable<TEntity>> | performGetAll | The repository PerformGetAll method. |
Returns
| Type | Description |
|---|---|
| TEntity[] | If |
Remarks
Get all the entities. Either from the cache or the repository depending on the implementation.
GetCached(TId)
Gets an entity from the cache.
Declaration
public override TEntity? GetCached(TId id)
Parameters
| Type | Name | Description |
|---|---|---|
| TId | id | The identifier. |
Returns
| Type | Description |
|---|---|
| TEntity | The entity with the specified identifier, if it is in the cache already, else null. |
Remarks
Does not consider the repository at all.
GetEntityCacheKey(int)
Declaration
protected string GetEntityCacheKey(int id)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id |
Returns
| Type | Description |
|---|---|
| string |
GetEntityCacheKey(TId?)
Declaration
protected string GetEntityCacheKey(TId? id)
Parameters
| Type | Name | Description |
|---|---|---|
| TId | id |
Returns
| Type | Description |
|---|---|
| string |
InsertEntities(TId[]?, TEntity[]?)
Declaration
protected virtual void InsertEntities(TId[]? ids, TEntity[]? entities)
Parameters
| Type | Name | Description |
|---|---|---|
| TId[] | ids | |
| TEntity[] | entities |
InsertEntity(string, TEntity)
Declaration
protected virtual void InsertEntity(string cacheKey, TEntity entity)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cacheKey | |
| TEntity | entity |
InsertNull(string)
Declaration
protected virtual void InsertNull(string cacheKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cacheKey |
Update(TEntity, Action<TEntity>)
Updates an entity.
Declaration
public override void Update(TEntity entity, Action<TEntity> persistUpdated)
Parameters
| Type | Name | Description |
|---|---|---|
| TEntity | entity | The entity. |
| Action<TEntity> | persistUpdated | The repository PersistUpdatedItem method. |
Remarks
Updates the entity in the repository, and updates the cache accordingly.