Ejemplo n.º 1
0
 internal static void Delete <TEntity>(DbContext dbContext, Expression <Func <TEntity, bool> > filter)
 {
     //1.清空Query缓存中关于该表的所有缓存记录
     QueryCacheManager.FlushTableCache(dbContext);
     //2.更新Table缓存中的该表记录
     TableCacheManager.DeleteCache(dbContext, filter);
 }
Ejemplo n.º 2
0
 internal static void Add <TEntity>(DbContext dbContext, IEnumerable <TEntity> entities)
 {
     //1.清空Query缓存中关于该表的所有缓存记录
     QueryCacheManager.FlushTableCache(dbContext);
     //2.更新Table缓存中的该表记录
     TableCacheManager.AddCache(dbContext, entities);
 }
Ejemplo n.º 3
0
        internal static T GetObject <T>(DbContext dbContext, Func <T> func) where T : class
        {
            //1.判断是否在一级QueryCahe中
            var result = QueryCacheManager.GetEntitiesFromCache <T>(dbContext);

            //2.如果都没有,则直接从逻辑中获取
            if (result == null)
            {
                result = func();
                dbContext.IsFromCache = false;
                //3.Query缓存存储逻辑(内涵缓存开启校验)
                QueryCacheManager.CacheData(dbContext, result);
            }

            return(result);
        }
Ejemplo n.º 4
0
        internal static TEntity GetEntity <TEntity>(DbContext dbContext, Expression <Func <TEntity, bool> > filter, Func <TEntity> func) where TEntity : class
        {
            //1.判断是否在二级TableCache,如果没有,则进行二级缓存初始化逻辑
            var result = TableCacheManager.GetEntitiesFromCache(dbContext, filter)?.FirstOrDefault();

            //2.判断是否在一级QueryCahe中
            if (result == null)
            {
                result = QueryCacheManager.GetEntitiesFromCache <TEntity>(dbContext);
            }

            //3.如果都没有,则直接从逻辑中获取
            if (result == null)
            {
                result = func();
                dbContext.IsFromCache = false;
                //4.Query缓存存储逻辑(内涵缓存开启校验)
                QueryCacheManager.CacheData(dbContext, result);
            }

            return(result);
        }
Ejemplo n.º 5
0
        internal static List <TEntity> GetEntities <TEntity>(DbContext dbContext, Expression <Func <TEntity, bool> > filter, Func <List <TEntity> > func) where TEntity : class
        {
            //1.判断是否在二级TableCache,如果没有,则进行二级缓存初始化逻辑
            var entities = TableCacheManager.GetEntitiesFromCache(dbContext, filter);

            //2.判断是否在一级QueryCahe中
            if (entities == null || !entities.Any())
            {
                entities = QueryCacheManager.GetEntitiesFromCache <List <TEntity> >(dbContext);
            }

            //3.如果都没有,则直接从逻辑中获取
            if (entities == null || !entities.Any())
            {
                entities = func();
                dbContext.IsFromCache = false;
                //4.Query缓存存储逻辑(内涵缓存开启校验)
                QueryCacheManager.CacheData(dbContext, entities);
            }

            return(entities);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 清空单个表相关的所有缓存
 /// </summary>
 internal static void FlushCurrentTableCache(DbContext dbContext)
 {
     QueryCacheManager.FlushTableCache(dbContext);
     TableCacheManager.FlushTableCache(dbContext);
 }