This commit is contained in:
sunkaixuan
2017-10-09 12:14:18 +08:00
parent cde72e02b4
commit 2f90c92de0
4 changed files with 38 additions and 17 deletions

View File

@@ -7,14 +7,10 @@ namespace SqlSugar
{ {
internal class CacheEngines internal class CacheEngines
{ {
public static string GetCacheMapping(CacheKey key) static string CacheMappingKey = "SqlSugarDataCacheMapping";
public static string GetCacheMapping(string tableName)
{ {
return null; return CacheMappingKey+ UtilConstants.Dot+tableName+ UtilConstants.Dot + Guid.NewGuid();
}
public static string GetCacheData(string key)
{
return null;
} }
} }
} }

View File

@@ -7,9 +7,23 @@ namespace SqlSugar
{ {
internal class CacheKeyBuider 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;
} }
} }
} }

View File

@@ -7,18 +7,24 @@ namespace SqlSugar
{ {
internal class CacheSchemeMain internal class CacheSchemeMain
{ {
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarClient context) public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarClient context)
{ {
CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder); CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder);
var mappingKey = CacheEngines.GetCacheMapping(key); string keyString = key.ToString();
T result = default(T); foreach (var tableName in key.Tables)
if (mappingKey.IsNullOrEmpty())
result = getData();
else
{ {
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; return result;
} }

View File

@@ -7,7 +7,12 @@ namespace SqlSugar
{ {
public class CacheKey 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 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);
}
} }
} }