From 2f90c92de009828a2f676fab58318232598d698f Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 9 Oct 2017 12:14:18 +0800 Subject: [PATCH] - --- .../SqlSugar/CacheScheme/CacheEngines.cs | 10 +++------- .../SqlSugar/CacheScheme/CacheKeyBuider.cs | 18 +++++++++++++++-- .../SqlSugar/CacheScheme/CacheSchemeMain.cs | 20 ++++++++++++------- Src/Asp.Net/SqlSugar/Entities/CacheKey.cs | 7 ++++++- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs b/Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs index 9de3113ed..bff13e884 100644 --- a/Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs +++ b/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(); } } } diff --git a/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs b/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs index d9e72e4a6..9ed5e3aa3 100644 --- a/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs +++ b/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs @@ -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(); + result.Tables.Add(context.EntityMaintenance.GetTableName(queryBuilder.EntityName)); + result.Tables.AddRange(queryBuilder.JoinQueryInfos.Select(it=>it.TableName)); + result.IdentificationList = new List(); + 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; } } } diff --git a/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs b/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs index 7e9a48c5f..774170d10 100644 --- a/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs +++ b/Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs @@ -7,18 +7,24 @@ namespace SqlSugar { internal class CacheSchemeMain { - public static T GetOrCreate(ICacheService cacheService, QueryBuilder queryBuilder, Func 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(tableName, keyString)); + //} } + + T result = default(T); + //if (mappingKey.IsNullOrEmpty()) + // result = getData(); + //else + //{ + // result = cacheService.GetOrCreate("", () => getData(), cacheDurationInSeconds); + //} return result; } diff --git a/Src/Asp.Net/SqlSugar/Entities/CacheKey.cs b/Src/Asp.Net/SqlSugar/Entities/CacheKey.cs index 6e6b49dfb..c9d942414 100644 --- a/Src/Asp.Net/SqlSugar/Entities/CacheKey.cs +++ b/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 Tables { get; set; } public List IdentificationList { get; set; } + public new string ToString() + { + return "SqlSugarDataCache." + UtilConstants.Dot + string.Join(UtilConstants.Dot, this.Tables) + string.Join(UtilConstants.Dot, this.IdentificationList); + } } }