public IQueryable <DomainType> GetAll(Expression <Func <DomainType, bool> > predicate = null) { //находим сущности в кеше var cachedItems = (predicate != null) ? CachedCollection.GetItems(cacheStorage).Where(predicate).AsEnumerable() : CachedCollection.GetItems(cacheStorage).AsEnumerable(); //делаем выборку из репозитория, исключая те сущности, что уже есть в кеше var repoItems = cachedItems.Union((predicate == null) ? repository.GetAll() : repository.GetAll(predicate)); //сохраняем выборку в кеше StoreItems(repoItems); return(repoItems.AsQueryable()); }
public DomainType Get(Expression <Func <DomainType, bool> > predicate) { //делаем выборку из кешированных данных var item = CachedCollection.GetItems(cacheStorage).Where(predicate).FirstOrDefault(); if (item == null) { //обращаемся к репозиторию item = repository.Get(predicate); if (item != null) { StoreItem(item); } } return(item); }