Exemple #1
0
 /// <summary>
 /// 标识为删除
 /// </summary>
 /// <param name="cacheKey">缓存项标识</param>
 /// <param name="entity">缓存的实体</param>
 /// <param name="cachingExpirationType">缓存期限类型</param>
 public async Task MarkDeletionAsync(string cacheKey, IEntity entity, CachingExpirationType cachingExpirationType)
 {
     if (entity is IDelEntity)
     {
         (entity as IDelEntity).IsDeletedInDatabase = true;
     }
     await this.RemoveAsync(cacheKey);
 }
Exemple #2
0
 /// <summary>
 /// 标识为删除
 /// </summary>
 /// <param name="cacheKey">缓存项标识</param>
 /// <param name="entity">缓存的实体</param>
 /// <param name="cachingExpirationType">缓存期限类型</param>
 public void MarkDeletion(string cacheKey, IEntity entity, CachingExpirationType cachingExpirationType)
 {
     if (entity is IDelEntity)
     {
         (entity as IDelEntity).IsDeletedInDatabase = true;
     }
     this.Remove(cacheKey);
 }
Exemple #3
0
        /// <summary>
        /// 获取前topNumber条Entity(启用缓存)
        /// </summary>
        /// <remarks>
        /// 一次性取出前SecondaryMaxRecords条记录
        /// </remarks>
        /// <param name="topNumber"></param>
        /// <param name="cachingExpirationTypes">缓存策略</param>
        /// <param name="getCacheKey">生成cacheKey的委托(CacheKey不要与topNumber相关)</param>
        /// <param name="generateSql">生成PetaPoco.Sql的委托</param>
        /// <returns></returns>
        protected virtual IEnumerable <TEntity> GetTopEntities(int topNumber, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <PetaPoco.Sql> generateSql)
        {
            PagingEntityIdCollection peic = null;
            string cacheKey = getCacheKey();

            peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
            if (peic == null)
            {
                IEnumerable <object> entityIds = CreateDAO().FetchTopPrimaryKeys <TEntity>(SecondaryMaxRecords, generateSql());
                peic = new PagingEntityIdCollection(entityIds);
                cacheService.Add(cacheKey, peic, cachingExpirationTypes);
            }

            IEnumerable <object> topEntityIds = peic.GetTopEntityIds(topNumber);

            return(PopulateEntitiesByEntityIds(topEntityIds));
        }
Exemple #4
0
        /// <summary>
        /// 获取分页查询数据(启用缓存)
        /// </summary>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="pageIndex">当前页码(从1开始)</param>
        /// <param name="cachingExpirationTypes">缓存策略</param>
        /// <param name="getCacheKey">生成cacheKey的委托</param>
        /// <param name="generateSql">生成PetaPoco.Sql的委托</param>
        /// <returns></returns>
        protected virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <PetaPoco.Sql> generateSql)
        {
            PagingEntityIdCollection peic = null;

            //modified by jiangshl:分页过大时缓存多页没有意义,所以加了pageSize <= SecondaryMaxRecords的限制
            if (pageIndex < CacheablePageCount && pageSize <= SecondaryMaxRecords)
            {
                string cacheKey = getCacheKey();
                peic = cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (peic == null)
                {
                    peic = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, generateSql());
                    peic.IsContainsMultiplePages = true;
                    cacheService.Add(cacheKey, peic, cachingExpirationTypes);
                }
            }
            else
            {
                peic = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize, pageIndex, generateSql());
            }

            IEnumerable <TEntity>   entitiesOfPage = PopulateEntitiesByEntityIds(peic.GetPagingEntityIds(pageSize, pageIndex));
            PagingDataSet <TEntity> pagingEntities = new PagingDataSet <TEntity>(entitiesOfPage)
            {
                PageIndex    = pageIndex,
                PageSize     = pageSize,
                TotalRecords = peic.TotalRecords
            };

            return(pagingEntities);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cacheKey"></param>
 /// <param name="value"></param>
 /// <param name="cachingExpirationType"></param>
 public void Set(string cacheKey, object value, CachingExpirationType cachingExpirationType)
 {
     Set(cacheKey, value, cachingExpirationDictionary[cachingExpirationType]);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cacheKey"></param>
 /// <param name="entity"></param>
 /// <param name="cachingExpirationType"></param>
 public void MarkDeletion(string cacheKey, IEntity entity, CachingExpirationType cachingExpirationType)
 {
     entity.IsDeletedInDatabase = true;
     cache.MarkDeletion(cacheKey, entity, cachingExpirationDictionary[cachingExpirationType]);
 }
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cacheKey"></param>
 /// <param name="values"></param>
 /// <param name="cachingExpirationType"></param>
 public void SetList <T>(string cacheKey, IEnumerable <T> values, CachingExpirationType cachingExpirationType)
 {
     cache.SetList(cacheKey, values, cachingExpirationDictionary[cachingExpirationType]);
 }
Exemple #8
0
        protected virtual System.Collections.Generic.IEnumerable <TEntity> GetTopEntities(int topNumber, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <Sql> generateSql)
        {
            string cacheKey = getCacheKey();
            PagingEntityIdCollection pagingEntityIdCollection = this.cacheService.Get <PagingEntityIdCollection>(cacheKey);

            if (pagingEntityIdCollection == null)
            {
                System.Collections.Generic.IEnumerable <object> entityIds = this.CreateDAO().FetchTopPrimaryKeys <TEntity>(this.SecondaryMaxRecords, generateSql());
                pagingEntityIdCollection = new PagingEntityIdCollection(entityIds);
                this.cacheService.Add(cacheKey, pagingEntityIdCollection, cachingExpirationTypes);
            }
            System.Collections.Generic.IEnumerable <object> topEntityIds = pagingEntityIdCollection.GetTopEntityIds(topNumber);
            return(this.PopulateEntitiesByEntityIds <object>(topEntityIds));
        }
Exemple #9
0
        protected virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <Sql> generateSql)
        {
            PagingEntityIdCollection pagingEntityIdCollection;

            if (pageIndex < this.CacheablePageCount && pageSize <= this.SecondaryMaxRecords)
            {
                string cacheKey = getCacheKey();
                pagingEntityIdCollection = this.cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (pagingEntityIdCollection == null)
                {
                    pagingEntityIdCollection = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize * this.CacheablePageCount, 1, generateSql());
                    pagingEntityIdCollection.IsContainsMultiplePages = true;
                    this.cacheService.Add(cacheKey, pagingEntityIdCollection, cachingExpirationTypes);
                }
            }
            else
            {
                pagingEntityIdCollection = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize, pageIndex, generateSql());
            }
            System.Collections.Generic.IEnumerable <TEntity> entities = this.PopulateEntitiesByEntityIds <object>(pagingEntityIdCollection.GetPagingEntityIds(pageSize, pageIndex));
            return(new PagingDataSet <TEntity>(entities)
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                TotalRecords = pagingEntityIdCollection.TotalRecords
            });
        }
Exemple #10
0
 /// <summary>
 /// 添加到缓存
 /// </summary>
 /// <param name="cacheKey">缓存项标识</param>
 /// <param name="value">缓存项</param>
 /// <param name="cachingExpirationType">缓存期限类型</param>
 public void Add(string cacheKey, object value, CachingExpirationType cachingExpirationType)
 {
     this.Add(cacheKey, value, this.cachingExpirationDictionary[cachingExpirationType]);
 }
Exemple #11
0
 /// <summary>
 /// 添加或更新缓存
 /// </summary>
 /// <param name="cacheKey">缓存项标识</param>
 /// <param name="value">缓存项</param>
 /// <param name="cachingExpirationType">缓存期限类型</param>
 public async Task SetAsync(string cacheKey, object value, CachingExpirationType cachingExpirationType)
 {
     await this.SetAsync(cacheKey, value, this.cachingExpirationDictionary[cachingExpirationType]);
 }
Exemple #12
0
        public virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <Sql> generateSql)
        {
            PagingEntityIdCollection ids = null;

            if ((pageIndex < this.CacheablePageCount) && (pageSize <= this.SecondaryMaxRecords))
            {
                string cacheKey = getCacheKey.Invoke();
                ids = this.cacheService.Get <PagingEntityIdCollection>(cacheKey);
                if (ids == null)
                {
                    ids = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize * this.CacheablePageCount, 1, generateSql.Invoke());
                    ids.IsContainsMultiplePages = true;
                    this.cacheService.Add(cacheKey, ids, cachingExpirationTypes);
                }
            }
            else
            {
                ids = this.CreateDAO().FetchPagingPrimaryKeys <TEntity>((long)this.PrimaryMaxRecords, pageSize, pageIndex, generateSql.Invoke());
            }
            return(new PagingDataSet <TEntity>(this.PopulateEntitiesByEntityIds <object>(ids.GetPagingEntityIds(pageSize, pageIndex)))
            {
                PageIndex = pageIndex, PageSize = pageSize, TotalRecords = ids.TotalRecords
            });
        }