mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
-
This commit is contained in:
@@ -7,14 +7,10 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheEngines
|
||||
{
|
||||
public static string GetCacheMapping(CacheKey key)
|
||||
static string CacheMappingKey = "SqlSugarDataCacheMapping";
|
||||
public static string GetCacheMapping(string tableName)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetCacheData(string key)
|
||||
{
|
||||
return null;
|
||||
return CacheMappingKey+ UtilConstants.Dot+tableName+ UtilConstants.Dot + Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,9 +7,23 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheKeyBuider
|
||||
{
|
||||
public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder)
|
||||
public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CacheKey result = new CacheKey();
|
||||
result.Database = context.Context.Ado.Connection.Database;
|
||||
result.Tables = new List<string>();
|
||||
result.Tables.Add(context.EntityMaintenance.GetTableName(queryBuilder.EntityName));
|
||||
result.Tables.AddRange(queryBuilder.JoinQueryInfos.Select(it=>it.TableName));
|
||||
result.IdentificationList = new List<string>();
|
||||
result.IdentificationList.Add(queryBuilder.GetTableNameString);
|
||||
result.IdentificationList.Add(queryBuilder.GetJoinValueString);
|
||||
result.IdentificationList.Add(queryBuilder.GetOrderByString);
|
||||
result.IdentificationList.Add(queryBuilder.GetGroupByString);
|
||||
result.IdentificationList.Add(queryBuilder.GetWhereValueString);
|
||||
result.IdentificationList.Add(queryBuilder.PartitionByValue);
|
||||
result.IdentificationList.Add(queryBuilder.Take.ObjToString());
|
||||
result.IdentificationList.Add(queryBuilder.Skip.ObjToString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,18 +7,24 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheSchemeMain
|
||||
{
|
||||
|
||||
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarClient context)
|
||||
{
|
||||
CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder);
|
||||
var mappingKey = CacheEngines.GetCacheMapping(key);
|
||||
T result = default(T);
|
||||
if (mappingKey.IsNullOrEmpty())
|
||||
result = getData();
|
||||
else
|
||||
string keyString = key.ToString();
|
||||
foreach (var tableName in key.Tables)
|
||||
{
|
||||
result = cacheService.GetOrCreate("", () => getData(), cacheDurationInSeconds);
|
||||
//if (!mappingInfo.Any(it=>it.Key.Equals(tableName,StringComparison.CurrentCultureIgnoreCase))) {
|
||||
// cacheService.Add<>(new KeyValuePair<string,string>(tableName, keyString));
|
||||
//}
|
||||
}
|
||||
|
||||
T result = default(T);
|
||||
//if (mappingKey.IsNullOrEmpty())
|
||||
// result = getData();
|
||||
//else
|
||||
//{
|
||||
// result = cacheService.GetOrCreate("", () => getData(), cacheDurationInSeconds);
|
||||
//}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,12 @@ namespace SqlSugar
|
||||
{
|
||||
public class CacheKey
|
||||
{
|
||||
public string[] Tables { get; set; }
|
||||
public string Database { get; set; }
|
||||
public List<string> Tables { get; set; }
|
||||
public List<string> IdentificationList { get; set; }
|
||||
public new string ToString()
|
||||
{
|
||||
return "SqlSugarDataCache." + UtilConstants.Dot + string.Join(UtilConstants.Dot, this.Tables) + string.Join(UtilConstants.Dot, this.IdentificationList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user