using System; using System.Collections.Generic; using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Cache { /// /// A base class for repository cache policies. /// /// The type of the entity. /// The type of the identifier. internal abstract class RepositoryCachePolicyBase : DisposableObject, IRepositoryCachePolicy where TEntity : class, IAggregateRoot { private Action _action; protected RepositoryCachePolicyBase(IRuntimeCacheProvider cache) { if (cache == null) throw new ArgumentNullException(nameof(cache)); Cache = cache; } protected IRuntimeCacheProvider Cache { get; } /// /// Disposing performs the actual caching action. /// protected override void DisposeResources() { _action?.Invoke(); } /// /// Sets the action to execute when being disposed. /// /// An action to perform when being disposed. protected void SetCacheAction(Action action) { _action = action; } /// public abstract TEntity Get(TId id, Func repoGet); /// public abstract TEntity Get(TId id); /// public abstract bool Exists(TId id, Func repoExists); /// public abstract void CreateOrUpdate(TEntity entity, Action repoCreateOrUpdate); /// public abstract void Remove(TEntity entity, Action repoRemove); /// public abstract TEntity[] GetAll(TId[] ids, Func> repoGet); } }