コード例 #1
0
        public override List <IHasId> GetAll()
        {
            this.Logger.LogVerbose("GetAll started", null);

            try
            {
                return(Decorated.GetAll());
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex.Message, null, ex);
                throw;
            }
            finally
            {
                this.Logger.LogVerbose("GetAll completed", null);
            }
        }
コード例 #2
0
ファイル: CachingRepository.cs プロジェクト: skippyfox/fursvp
        /// <summary>
        /// Gets a result set containing all documents for the entity type from the cache, or via the decorated method if not yet cached.
        /// If not already cached, then an index is built and the index and all entities retrieved are cached.
        /// </summary>
        /// <returns>An <see cref="IQueryable{T}"/> against which further filtering can be applied on the result set.</returns>
        public async Task <IQueryable <T> > GetAll()
        {
            if (MemoryCache.TryGetValue(IndexCacheKey, out List <Guid> guids))
            {
                return(guids.Select(g =>
                {
                    var entity = MemoryCache.Get <T>(g);
                    return Mapper.Map <T, T>(entity);
                }).AsQueryable());
            }

            var      allEntities = (await Decorated.GetAll().ConfigureAwait(false)).ToList();
            DateTime expiration  = DateTime.Now.AddMinutes(5); // TODO - put magic number into config

            MemoryCache.Set(IndexCacheKey, allEntities.Select(e => e.Id).ToList(), expiration);

            foreach (var e in allEntities)
            {
                CacheCopyOfEntity(e, expiration);
            }

            return(allEntities.AsQueryable());
        }
コード例 #3
0
 protected virtual void GetAllOnThread(ListReturnCallback callback)
 {
     callback(Decorated.GetAll());
 }