Esempio n. 1
0
        public async Task InsertAsync(T entity)
        {
            entity.Created = ITimeService.Now;
            entity.AutoId  = await IAutoIdService.GetNext <T>();

            await IDatabaseService.InsertAsync(entity);

            await IEntityCacheService.SetAsync(entity);
        }
Esempio n. 2
0
        public async Task <IDynamicCollection <T> > GetOrCreateAsync <T>(
            string listName,
            Func <IQueryable <T>, IQueryable <T> > query    = null,
            Func <IEnumerable <T>, IEnumerable <T> > sorter = null
            )
            where T : IEntity
        {
            var collectionKey = GetCollectionCacheKey(listName);

            var result =
                IMemoryCacheService.Get <IDynamicCollection <T> >(collectionKey);

            if (result != null)
            {
                return(result);
            }

            var IRepository = IContainerService.Get <IRepository <T> >();

            var idsKey    = GetIdsCacheKey(listName);
            var entityIds = await ICacheService.GetAsync <List <string> >(idsKey);

            if (entityIds == null)
            {
                var queryable = IRepository.GetQueryable();

                if (query != null)
                {
                    queryable = query(queryable);
                }

                var entities = await IDatabaseService.QueryAsync(queryable);

                await IEntityCacheService.Push(entities);

                entityIds =
                    entities
                    .Select(x => x?.Id)
                    .ToList();
            }
            else
            {
                await IRepository.GetManyByIdAsync(entityIds);
            }

            result =
                IDynamicCollectionFactory
                .Create(entityIds, sorter);

            IMemoryCacheService.Set(collectionKey, result);

            return(result);
        }
Esempio n. 3
0
        public async Task <IEnumerable <T> > GetManyByIdAsync(IEnumerable <string> ids)
        {
            var cached = await IEntityCacheService.GetManyByIdAsync <T>(ids);

            var cachedIds = cached.Select(x => x.Id);

            var uncachedIds = ids.Except(cachedIds);
            var uncached    = await IDatabaseService.GetManyByIdAsync <T>(uncachedIds);

            await IEntityCacheService.Push(uncached);

            cached = await IEntityCacheService.GetManyByIdAsync <T>(ids);

            return(cached);
        }
Esempio n. 4
0
        public async Task <T> GetByIdAsync(string id)
        {
            var result = await IEntityCacheService.GetByIdAsync <T>(id);

            if (result == null)
            {
                result = await IDatabaseService.GetByIdAsync <T>(id);

                if (result != null)
                {
                    await IEntityCacheService.SetAsync(result);
                }
            }

            return(result);
        }
 public LookupCacheService(IEntityCacheService <TEntity, TTransaction> cacheService)
 {
     _cacheService = cacheService;
 }
Esempio n. 6
0
        public async Task <T> GetByNameAsync(string name)
        {
            var id = await IIdTranslationService.GetIdByNameAsync <T>(name);

            return(await IEntityCacheService.GetByIdAsync <T>(id));
        }
Esempio n. 7
0
        public async Task <T> GetByAutoIdAsync(ulong autoId)
        {
            var id = await IIdTranslationService.GetIdByAutoIdAsync <T>(autoId);

            return(await IEntityCacheService.GetByIdAsync <T>(id));
        }
Esempio n. 8
0
        public async Task SaveAsync(T entity)
        {
            await IDatabaseService.SaveAsync(entity);

            await IEntityCacheService.SetAsync(entity);
        }
Esempio n. 9
0
        public async Task RemoveAsync(T entity)
        {
            await IDatabaseService.RemoveAsync <T>(entity.Id);

            await IEntityCacheService.RemoveAsync <T>(entity.Id);
        }
 public static IList <TEntity> GetAllActiveSorted <TEntity, TTransaction>(this IEntityCacheService <TEntity, TTransaction> items, int?id = null)
     where TEntity : class, IIsActive, INamedEntity, IEntityWithIntKey
     where TTransaction : ITransaction
 {
     return(items.GetAll().GetAllActiveSorted(id));
 }
 public static IList <TEntity> GetAllSorted <TEntity, TTransaction>(this IEntityCacheService <TEntity, TTransaction> items)
     where TEntity : class, INamedEntity, IGetIdentifier
     where TTransaction : ITransaction
 {
     return(items.GetAll().GetAllSorted());
 }