namespace zero.Collections; public record CachableEntityCollectionOptions(bool CacheIndividual, bool CacheAll); public abstract class CachableEntityCollection : EntityCollection where T : ZeroIdEntity, new() { protected CachableEntityCollectionOptions CacheOptions { get; set; } protected ICollectionCache Cache { get; set; } public CachableEntityCollection(ICollectionContext collectionContext, ICollectionCache collectionCache) : base(collectionContext) { CacheOptions = new(CacheIndividual: true, CacheAll: false); // TODO when props update we need to update Cache.For() Cache = collectionCache.For(CacheOptions); } /// public override async Task Load(string id, string changeVector = null) { if (changeVector.IsNullOrEmpty() && Cache.TryGetValue(id, out T model)) { return model; } return await base.Load(id, changeVector); } /// public override Task> Load(IEnumerable ids) { return base.Load(ids); } }