Exemplo n.º 1
0
        internal async Task <long> GetCountAsync <TEntity>(Expression <Func <TEntity, bool> > filter, Func <Task <long> > funcAsync) where TEntity : class
        {
            long?result = null;

            //1.Determine whether query data exists in Table Cache, if not, begin to initialize Table Caching Operation
            if (DbContext.OpenTableCache)
            {
                result = TableCacheManager.GetEntitiesFromCache(filter)?.Count;
            }

            //2.Determine whether query data exists in Query Cache
            if (DbContext.OpenQueryCache)
            {
                if (result == null)
                {
                    result = QueryCacheManager.GetEntitiesFromCache <long?>();
                }
            }

            //3.if not in both Table Cache and Query Cache, query data from Query logic
            if (result == null || result == default(long))
            {
                result = await funcAsync();

                DbContext.IsFromCache = false;
                //4.Cache Query result to Query Cache
                QueryCacheManager.CacheData(result);
            }

            return(result ?? default(long));
        }
Exemplo n.º 2
0
        internal async Task <List <TEntity> > GetEntitiesAsync <TEntity>(Expression <Func <TEntity, bool> > filter, Func <Task <List <TEntity> > > funcAsync) where TEntity : class
        {
            List <TEntity> entities = null;

            //1.Determine whether query data exists in Table Cache, if not, begin to initialize Table Caching Operation
            if (DbContext.OpenTableCache)
            {
                entities = TableCacheManager.GetEntitiesFromCache(filter);
            }

            //2.Determine whether query data exists in Query Cache
            if (DbContext.OpenQueryCache)
            {
                if (entities == null || !entities.Any())
                {
                    entities = QueryCacheManager.GetEntitiesFromCache <List <TEntity> >();
                }
            }

            //3.if not in both Table Cache and Query Cache, query data from Query logic
            if (entities == null || !entities.Any())
            {
                entities = await funcAsync();

                DbContext.IsFromCache = false;
                //4.Cache Query result to Query Cache
                QueryCacheManager.CacheData(entities);
            }

            return(entities);
        }
Exemplo n.º 3
0
        internal TEntity GetEntity <TEntity>(Expression <Func <TEntity, bool> > filter, Func <TEntity> func) where TEntity : class
        {
            TEntity result = null;

            //1.Determine whether query data exists in Table Cache, if not, begin to initialize Table Caching Operation
            if (DbContext.OpenTableCache)
            {
                result = TableCacheManager.GetEntitiesFromCache(filter)?.FirstOrDefault();
            }

            //2.Determine whether query data exists in Query Cache
            if (DbContext.OpenQueryCache)
            {
                if (result == null)
                {
                    result = QueryCacheManager.GetEntitiesFromCache <TEntity>();
                }
            }

            //3.if not in both Table Cache and Query Cache, query data from Query logic
            if (result == null || result == default(TEntity))
            {
                result = func();
                DbContext.IsFromCache = false;
                //4.Cache Query result to Query Cache
                QueryCacheManager.CacheData(result);
            }

            return(result);
        }
Exemplo n.º 4
0
 internal void Update <TEntity>(TEntity entity, Expression <Func <TEntity, bool> > filter, IEnumerable <string> updateCloumns = null)
 {
     if (DbContext.OpenQueryCache)
     {
         QueryCacheManager.FlushCollectionCache();
     }
     if (DbContext.OpenTableCache)
     {
         TableCacheManager.UpdateCache(entity, filter, updateCloumns);
     }
 }
Exemplo n.º 5
0
 internal void Add <TEntity>(IEnumerable <TEntity> entities)
 {
     if (DbContext.OpenQueryCache)
     {
         QueryCacheManager.FlushCollectionCache();
     }
     if (DbContext.OpenTableCache)
     {
         TableCacheManager.AddCache(entities);
     }
 }
Exemplo n.º 6
0
 //Same Logic:
 //1.Clear all cached records about the table in the query cache
 //2.Update the table record in the table cache
 internal void Add <TEntity>(TEntity entity)
 {
     if (DbContext.OpenQueryCache)
     {
         QueryCacheManager.FlushCollectionCache();
     }
     if (DbContext.OpenTableCache)
     {
         TableCacheManager.AddCache(entity);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Clear single table's all caching data
 /// </summary>
 public void FlushCurrentCollectionCache(string collectionName = null)
 {
     if (DbContext.OpenQueryCache)
     {
         QueryCacheManager.FlushCollectionCache(collectionName);
     }
     if (DbContext.OpenTableCache)
     {
         TableCacheManager.FlushCollectionCache(collectionName);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Clear All Cache
 /// </summary>
 public void FlushAllCache()
 {
     if (DbContext.OpenQueryCache)
     {
         QueryCacheManager.FlushAllCache();
     }
     if (DbContext.OpenTableCache)
     {
         TableCacheManager.FlushAllCache();
     }
 }
Exemplo n.º 9
0
 internal void Delete <TEntity>(Expression <Func <TEntity, bool> > filter)
 {
     if (DbContext.OpenQueryCache)
     {
         QueryCacheManager.FlushCollectionCache();
     }
     if (DbContext.OpenTableCache)
     {
         TableCacheManager.DeleteCache(filter);
     }
 }
Exemplo n.º 10
0
        internal T GetObject <T>(Func <T> func) where T : class
        {
            T result = null;

            //1.Determine whether query data exists in Query Cache
            if (DbContext.OpenTableCache)
            {
                result = QueryCacheManager.GetEntitiesFromCache <T>();
            }

            //2.if not in Query Cache, query data from Query logic
            if (result == null)
            {
                result = func();
                DbContext.IsFromCache = false;
                //3.Cache Query result to Query Cache
                QueryCacheManager.CacheData(result);
            }

            return(result);
        }
Exemplo n.º 11
0
 internal DbCacheManager(DbContext context) : base(context)
 {
     QueryCacheManager = new QueryCacheManager(context);
     TableCacheManager = new TableCacheManager(context);
 }