/// <summary> /// 缓存 /// </summary> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="cacheType">缓存的类型</param> /// <param name="sql"></param> /// <param name="sqlParams">sql的参数</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static TRtn CacheUseDict <TRtn>(this IEFQueryCache cache, string tableName, string cacheType, string sql, IDictionary <string, object> sqlParams, Func <TRtn> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, cacheType, EFHelper.Services.EFCoreExUtility.CombineSqlAndParamsToString(sql, sqlParams), toDBGet, expiryPolicy)); }
public void Execute(ILuaSqlExecutePolicyExecutorInfo info) { string defCacheType = null; //query和scalar才进行缓存 if (info.ExecuteType == ConfigSqlExecuteType.query) { defCacheType = QueryCacheExtensions.CacheType; } else if (info.ExecuteType == ConfigSqlExecuteType.scalar) { defCacheType = ScalarCacheExtensions.CacheType; } if (defCacheType != null) { //执行缓存策略 var policy = info.GetPolicy() as SqlL2QueryCachePolicy; //是否配置了查询缓存 if (IsUsePolicy(policy)) { var cacheType = string.IsNullOrEmpty(policy.Type) ? defCacheType : policy.Type; var rtn = _cache.Cache(info.TableName, cacheType, _util.CombineSqlAndParamsToString(info.Sql, info.SqlParams), info.ToDBExecutor, policy.Expiry, info.ReturnType); info.ReturnValue = rtn; //执行缓存成功,那么结束 info.IsEnd = true; } } }
/// <summary> /// 缓存 /// </summary> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="cacheType">缓存的类型</param> /// <param name="sql"></param> /// <param name="sqlParamModel">sql的参数模型对象</param> /// <param name="ignoreProptsForParamModel">sql的参数模型对象中需要忽略的属性名</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static TRtn CacheUseModel <TRtn>(this IEFQueryCache cache, string tableName, string cacheType, string sql, object sqlParamModel, IEnumerable <string> ignoreProptsForParamModel, Func <TRtn> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, cacheType, EFHelper.Services.EFCoreExUtility.CombineSqlAndParamsToString(sql, EFHelper.Services.ObjReflector.GetPublicInstanceProptValues(sqlParamModel, ignoreProptsForParamModel)), toDBGet, expiryPolicy)); }
/// <summary> /// 缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="cacheType">缓存的类型</param> /// <param name="sql"></param> /// <param name="sqlParams">sql的参数</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static TRtn Cache <TEntity, TRtn>(this IEFQueryCache cache, string cacheType, string sql, ICollection <IDataParameter> sqlParams, Func <TRtn> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(typeof(TEntity), cacheType, sql, sqlParams, toDBGet, expiryPolicy)); }
/// <summary> /// 缓存 /// </summary> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="tableEntityType">表的实体类型(用于获取表名)</param> /// <param name="cacheType">缓存的类型</param> /// <param name="cacheKey"></param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static TRtn Cache <TRtn>(this IEFQueryCache cache, Type tableEntityType, string cacheType, string cacheKey, Func <TRtn> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(EFHelper.Services.EFCoreExUtility.GetTableName(tableEntityType), cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// LongCount缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="query"></param> /// <param name="expiry">缓存过期时间</param> /// <returns></returns> public static long LongCountCache <TEntity, T>(this IEFQueryCache cache, IQueryable <T> query, DateTime expiry) { return(cache.Cache <TEntity, long>(_cacheType, query, () => query.LongCount(), expiry)); }
/// <summary> /// FirstOrDefault缓存 /// </summary> /// <typeparam name="T">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="cacheKey">缓存的类型</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static T FirstOrDefaultCache <T>(this IEFQueryCache cache, string tableName, string cacheKey, Func <T> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// FirstOrDefault缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="query"></param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static T FirstOrDefaultCache <TEntity, T>(this IEFQueryCache cache, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache <TEntity, T>(_cacheType, query, () => query.FirstOrDefault(), expiryPolicy)); }
/// <summary> /// ToList缓存 /// </summary> /// <typeparam name="T">List缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="cacheKey">缓存的key</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static IReadOnlyList <T> ListCache <T>(this IEFQueryCache cache, string tableName, string cacheKey, Func <IReadOnlyList <T> > toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// ToList缓存 /// </summary> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="query"></param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static IReadOnlyList <T> ListCache <T>(this IEFQueryCache cache, string tableName, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, query, () => query.ToList(), expiryPolicy)); }
/// <summary> /// ToList缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="query"></param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static IReadOnlyList <T> ListCache <TEntity, T>(this IEFQueryCache cache, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache <TEntity, IReadOnlyList <T> >(_cacheType, query, () => query.ToList(), expiryPolicy)); }
/// <summary> /// Count缓存 /// </summary> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="query"></param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static int CountCache <T>(this IEFQueryCache cache, string tableName, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, query, () => query.Count(), expiryPolicy)); }
/// <summary> /// Count缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="query">IQueryable</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static int CountCache <TEntity, T>(this IEFQueryCache cache, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache <TEntity, int>(_cacheType, query, () => query.Count(), expiryPolicy)); }
/// <summary> /// LongCount缓存 /// </summary> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="cacheKey"></param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static long LongCountCache(this IEFQueryCache cache, string tableName, string cacheKey, Func <long> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// LongCount缓存 /// </summary> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="tableEntityType">表的实体类型(用于获取表名)</param> /// <param name="query"></param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static long LongCountCache <T>(this IEFQueryCache cache, Type tableEntityType, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableEntityType, _cacheType, query, () => query.LongCount(), expiryPolicy)); }
/// <summary> /// SqlScalar缓存(缓存的类型为:scalar) /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <param name="cache"></param> /// <param name="cacheKey">缓存的key</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static object ScalarCache <TEntity>(this IEFQueryCache cache, string cacheKey, Func <object> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache <TEntity, object>(_cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// SqlScalar缓存(缓存的类型为:scalar) /// </summary> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="cacheKey">缓存的key</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static object ScalarCache(this IEFQueryCache cache, string tableName, string cacheKey, Func <object> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// 缓存 /// </summary> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="tableEntityType">表的实体类型(用于获取表名)</param> /// <param name="cacheType">缓存的类型</param> /// <param name="sql"></param> /// <param name="sqlParams">sql的参数</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static TRtn Cache <TRtn>(this IEFQueryCache cache, Type tableEntityType, string cacheType, string sql, ICollection <IDataParameter> sqlParams, Func <TRtn> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(EFHelper.Services.EFCoreExUtility.GetTableName(tableEntityType), cacheType, sql, sqlParams, toDBGet, expiryPolicy)); }
/// <summary> /// FirstOrDefault缓存 /// </summary> /// <typeparam name="T">IQueryable的泛型类型</typeparam> /// <param name="cache"></param> /// <param name="tableName">表名</param> /// <param name="query"></param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static T FirstOrDefaultCache <T>(this IEFQueryCache cache, string tableName, IQueryable <T> query, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(tableName, _cacheType, query, () => query.FirstOrDefault(), expiryPolicy)); }
/// <summary> /// 缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="cacheType">缓存的类型</param> /// <param name="query"></param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiry">缓存过期时间</param> /// <returns></returns> public static TRtn Cache <TEntity, TRtn>(this IEFQueryCache cache, string cacheType, IQueryable query, Func <TRtn> toDBGet, DateTime expiry) { return(cache.Cache(typeof(TEntity), cacheType, query, toDBGet, new QueryCacheExpiryPolicy(expiry))); }
/// <summary> /// 缓存 /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="TRtn">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="cacheType">缓存的类型</param> /// <param name="cacheKey">缓存的key</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static TRtn Cache <TEntity, TRtn>(this IEFQueryCache cache, string cacheType, string cacheKey, Func <TRtn> toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache(typeof(TEntity), cacheType, cacheKey, toDBGet, expiryPolicy)); }
/// <summary> /// SqlQuery缓存(缓存的类型为:query) /// </summary> /// <typeparam name="TEntity">表的实体类型(用于获取表名)</typeparam> /// <typeparam name="T">缓存的数据类型</typeparam> /// <param name="cache"></param> /// <param name="cacheKey">缓存的key</param> /// <param name="toDBGet">用于初始化缓存数据(例如:到数据库获取数据进行缓存的操作)</param> /// <param name="expiryPolicy">缓存过期策略</param> /// <returns></returns> public static IReadOnlyList <T> QueryCache <TEntity, T>(this IEFQueryCache cache, string cacheKey, Func <IReadOnlyList <T> > toDBGet, IQueryCacheExpiryPolicy expiryPolicy) { return(cache.Cache <TEntity, IReadOnlyList <T> >(_cacheType, cacheKey, toDBGet, expiryPolicy)); }