public IEnumerable <T> GetCacheItemsByKeySearch <T>(string keyStartsWith)
 {
     if (_enableCache == false)
     {
         return(_nullHttpCache.GetCacheItemsByKeySearch <T>(keyStartsWith));
     }
     else
     {
         return(_httpCache.GetCacheItemsByKeySearch <T>(keyStartsWith));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Gets all entities of type TEntity or a list according to the passed in Ids
        /// </summary>
        /// <param name="keys">The keys of the entities to be returned</param>
        /// <returns>A collection of entities</returns>
        public IEnumerable <TEntity> GetAll(params Guid[] keys)
        {
            if (keys.Any())
            {
                var entities = new List <TEntity>();

                foreach (var key in keys)
                {
                    var entity = _cache.GetCacheItem(GetCacheKey(key));
                    if (entity != null)
                    {
                        entities.Add((TEntity)entity);
                    }
                }

                if (entities.Count().Equals(keys.Count()) && entities.Any(x => x == null) == false)
                {
                    return(entities);
                }
            }
            else
            {
                // fix http://issues.merchello.com/youtrack/issue/M-159
                // Since IProduct and IProductVaraint both start with IProduct which was causing the cache conflict
                var allEntities = _cache.GetCacheItemsByKeySearch(typeof(TEntity).Name + ".").ToArray();

                ////_cache.GetAllByType(typeof(TEntity));

                if (allEntities.Any())
                {
                    var query = Querying.Query <TEntity> .Builder.Where(x => x.Key != Guid.Empty);

                    var totalCount = PerformCount(query);

                    if (allEntities.Count() == totalCount)
                    {
                        return(allEntities.Select(x => (TEntity)x));
                    }
                }
            }

            var entityCollection = PerformGetAll(keys).ToArray();

            foreach (var entity in entityCollection)
            {
                if (entity != null)
                {
                    _cache.GetCacheItem(GetCacheKey(entity.Key), () => entity);
                }
            }

            return(entityCollection);
        }
Beispiel #3
0
        /// <summary>
        /// Gets all entities of type TEntity or a list according to the passed in Guid Keys
        /// </summary>
        /// <param name="keys">The keys of the entities to be returned</param>
        /// <returns>A collection of entities</returns>
        public IEnumerable <TEntity> GetAll(params Guid[] Keys)
        {
            if (Keys.Any())
            {
                var entities = new List <TEntity>();

                foreach (var key in Keys)
                {
                    var entity = _cache.GetCacheItem(GetCacheKey(key));
                    if (entity != null)
                    {
                        entities.Add((TEntity)entity);
                    }
                }

                if (entities.Count().Equals(Keys.Count()) && entities.Any(x => x.Equals(default(TEntity))) == false)
                {
                    return(entities);
                }
            }
            else
            {
                var allEntities = _cache.GetCacheItemsByKeySearch(typeof(TEntity).Name + ".").ToArray();


                if (allEntities.Any())
                {
                    var query      = this.GetBaseQuery(true);
                    var totalCount = PerformCount(query);

                    if (allEntities.Count() == totalCount)
                    {
                        return(allEntities.Select(x => (TEntity)x));
                    }
                }
            }

            var entityCollection = PerformGetAll(Keys).ToArray();

            foreach (var entity in entityCollection)
            {
                if (!entity.Equals(default(TEntity)))
                {
                    var en = entity;
                    _cache.GetCacheItem(GetCacheKey(entity.Key), () => en);
                }
            }

            return(entityCollection);
        }