public virtual void UpdateMemberCache(Guid memberId)
        {
            var updatedMember    = GetFromSqlOrNone(memberId);
            var allCachedMembers = GetAll();


            var updatedCache = updatedMember != null
                ? allCachedMembers.WithUpdatedElement(el => el.Id == memberId, updatedMember)
                : allCachedMembers.Where(el => el.Id != memberId);

            _cacheService.Set(MembersCacheKey, updatedCache.ToArray(), CacheHelper.GetMidnightUtcDateTimeOffset());
        }
        public virtual void UpdateMemberCache(IEnumerable <Guid> memberIds)
        {
            var allCachedMembers = GetAll()
                                   .ToArray();

            var updatedMembers = memberIds
                                 .SelectMany(id =>
            {
                var member = GetFromSqlOrNone(id);
                return(member != null
                        ? allCachedMembers.WithUpdatedElement(el => el.Id == id, member)
                        : allCachedMembers.Where(el => el.Id != id));
            })
                                 .ToArray();

            _cacheService.Set(MembersCacheKey, updatedMembers, CacheHelper.GetMidnightUtcDateTimeOffset());
        }
        public virtual async Task <IEnumerable <T> > GetAllAsync()
        {
            var members = await _cacheService.GetOrSetAsync(async() => (await GetAllFromSqlAsync()).ToList(), MembersCacheKey, CacheHelper.GetMidnightUtcDateTimeOffset());

            return(members);
        }
        public virtual void DeleteFromCache(Guid memberId)
        {
            var updatedCache = GetAll().Where(el => el.Id != memberId).ToList();

            _cacheService.Set(MembersCacheKey, updatedCache, CacheHelper.GetMidnightUtcDateTimeOffset());
        }
        public virtual IEnumerable <T> GetAll()
        {
            var members = _cacheService.GetOrSet(MembersCacheKey, () => GetAllFromSql().ToList(), CacheHelper.GetMidnightUtcDateTimeOffset());

            return(members);
        }
 public virtual async Task DeleteFromCacheAsync(Guid memberId)
 {
     await _cacheService.SetAsync(async() => (await GetAllAsync()).Where(el => el.Id != memberId).ToList(), MembersCacheKey, CacheHelper.GetMidnightUtcDateTimeOffset());
 }
        public virtual async Task UpdateMemberCacheAsync(IEnumerable <Guid> memberIds)
        {
            var allCachedMembers = await GetAllAsync();

            foreach (var memberId in memberIds)
            {
                IEnumerable <T> updatedCache;
                T updatedMember = await GetFromSqlOrNoneAsync(memberId);

                if (updatedMember != null)
                {
                    updatedCache = allCachedMembers.WithUpdatedElement(el => el.Id == memberId, updatedMember);
                }
                else
                {
                    updatedCache = allCachedMembers.Where(el => el.Id != memberId);
                }
            }

            await _cacheService.SetAsync(() => Task.FromResult(allCachedMembers.ToList()), MembersCacheKey, CacheHelper.GetMidnightUtcDateTimeOffset());
        }