/// <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 = RuntimeCache.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 = RuntimeCache.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)
                {
                    RuntimeCache.GetCacheItem(GetCacheKey(entity.Key), () => entity);
                }
            }

            return(entityCollection);
        }
Beispiel #2
0
 public IEnumerable <T> GetCacheItemsByKeySearch <T>(string keyStartsWith)
 {
     return(RuntimeCache.GetCacheItemsByKeySearch <T>(keyStartsWith));
 }