Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
2f90c92de0
  1. 10
      Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs
  2. 16
      Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs
  3. 20
      Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs
  4. 7
      Src/Asp.Net/SqlSugar/Entities/CacheKey.cs

10
Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs

@ -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();
}
}
}

16
Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs

@ -9,7 +9,21 @@ namespace SqlSugar
{
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;
}
}
}

20
Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs

@ -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
Src/Asp.Net/SqlSugar/Entities/CacheKey.cs

@ -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);
}
}
}

Loading…
Cancel
Save