using System; using System.Collections.Generic; using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Cache { internal abstract class RepositoryCachePolicyBase : DisposableObject, IRepositoryCachePolicy where TEntity : class, IAggregateRoot { private Action _action; protected RepositoryCachePolicyBase(IRuntimeCacheProvider cache) { if (cache == null) throw new ArgumentNullException("cache"); Cache = cache; } protected IRuntimeCacheProvider Cache { get; private set; } /// /// The disposal performs the caching /// protected override void DisposeResources() { if (_action != null) { _action(); } } /// /// Sets the action to execute on disposal /// /// protected void SetCacheAction(Action action) { _action = action; } public abstract TEntity Get(TId id, Func getFromRepo); public abstract TEntity Get(TId id); public abstract bool Exists(TId id, Func getFromRepo); public abstract void CreateOrUpdate(TEntity entity, Action persistMethod); public abstract void Remove(TEntity entity, Action persistMethod); public abstract TEntity[] GetAll(TId[] ids, Func> getFromRepo); } }