예제 #1
0
        public async Task <IEntity[]> GetList()
        {
            if (!IsCacheable())
            {
                return(await LoadFromDatabase().ToArray());
            }

            if (Criteria.Any() || Context.Current.Database().AnyOpenTransaction())
            {
                return(await LoadFromDatabaseAndCache().ToArray());
            }

            var result = Cache.GetList(EntityType)?.Cast <IEntity>().ToArray();

            if (result != null)
            {
                await LoadIncludedAssociations(result);

                return(result);
            }

            result = await LoadFromDatabaseAndCache().ToArray();

            Cache.AddList(EntityType, result);

            return(result);
        }
        public async Task <IEnumerable <IEntity> > GetList()
        {
            if (!IsCacheable())
            {
                return(await LoadFromDatabase());
            }

            var cacheKey = GetCacheKey();

            var result = Cache.GetList(EntityType, cacheKey)?.Cast <IEntity>();

            if (result != null)
            {
                await LoadIncludedAssociations(result);

                return(result);
            }

            result = await LoadFromDatabaseAndCache();

            // If there is no transaction open, cache it:
            if (!Context.Current.Database().AnyOpenTransaction())
            {
                Cache.AddList(EntityType, cacheKey, result);
            }

            return(result);
        }