using System; using System.Collections.Generic; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Scoping; namespace Umbraco.Core.Cache { internal interface IRepositoryCachePolicy where TEntity : class, IAggregateRoot { // note: // at the moment each repository instance creates its corresponding cache policy instance // we could reduce allocations by using static cache policy instances but then we would need // to modify all methods here to pass the repository and cache eg: // // TEntity Get(TRepository repository, IRuntimeCacheProvider cache, TId id); // // it is not *that* complicated but then RepositoryBase needs to have a TRepository generic // type parameter and it all becomes convoluted - keeping it simple for the time being. /// /// Creates a scoped version of this cache policy. /// /// The global isolated runtime cache for this policy. /// The scope. /// When a policy is scoped, it means that it has been created with a scoped /// isolated runtime cache, and now it needs to be wrapped into something that can apply /// changes to the global isolated runtime cache. IRepositoryCachePolicy Scoped(IRuntimeCacheProvider runtimeCache, IScope scope); /// /// Gets an entity from the cache, else from the repository. /// /// The identifier. /// The repository PerformGet method. /// The repository PerformGetAll method. /// The entity with the specified identifier, if it exits, else null. /// First considers the cache then the repository. TEntity Get(TId id, Func performGet, Func> performGetAll); /// /// Gets an entity from the cache. /// /// The identifier. /// The entity with the specified identifier, if it is in the cache already, else null. /// Does not consider the repository at all. TEntity GetCached(TId id); /// /// Gets a value indicating whether an entity with a specified identifier exists. /// /// The identifier. /// The repository PerformExists method. /// The repository PerformGetAll method. /// A value indicating whether an entity with the specified identifier exists. /// First considers the cache then the repository. bool Exists(TId id, Func performExists, Func> performGetAll); /// /// Creates an entity. /// /// The entity. /// The repository PersistNewItem method. /// Creates the entity in the repository, and updates the cache accordingly. void Create(TEntity entity, Action persistNew); /// /// Updates an entity. /// /// The entity. /// The reopsitory PersistUpdatedItem method. /// Updates the entity in the repository, and updates the cache accordingly. void Update(TEntity entity, Action persistUpdated); /// /// Removes an entity. /// /// The entity. /// The repository PersistDeletedItem method. /// Removes the entity from the repository and clears the cache. void Delete(TEntity entity, Action persistDeleted); /// /// Gets entities. /// /// The identifiers. /// The repository PerformGetAll method. /// If is empty, all entities, else the entities with the specified identifiers. /// Get all the entities. Either from the cache or the repository depending on the implementation. TEntity[] GetAll(TId[] ids, Func> performGetAll); /// /// Clears the entire cache. /// void ClearAll(); } }