From 29c3a12bcf4a20bdd6563a968de6c4148c9a87e3 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 31 Dec 2018 13:50:10 +0800 Subject: [PATCH] Cache Bug --- Src/Asp.Net/ExtensionsDemo/CacheDemo.cs | 4 ++-- .../SqlSugar/CacheScheme/CacheKeyBuider.cs | 2 +- Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs b/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs index b369903d2..4ca070ba3 100644 --- a/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs +++ b/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs @@ -12,8 +12,8 @@ namespace ExtensionsDemo { public static void Init() { - //HttpRuntimeCache(); - RedisCache(); + HttpRuntimeCache(); + //RedisCache(); } diff --git a/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs b/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs index 4b6155ccc..3168d87b3 100644 --- a/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs +++ b/Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs @@ -28,7 +28,7 @@ namespace SqlSugar result.IdentificationList.Add(queryBuilder.Take.ObjToString()); result.IdentificationList.Add(queryBuilder.Skip.ObjToString()); result.IdentificationList.Add(queryBuilder.IsCount.ObjToString()); - result.IdentificationList.Add(queryBuilder.GetSelectValue.ObjToString().Length.ObjToString()); + result.IdentificationList.Add(UtilMethods.GetMD5(queryBuilder.GetSelectValue.ObjToString())); if (queryBuilder.Parameters.HasValue()) { foreach (var item in queryBuilder.Parameters) diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index 945aaf8c3..dc20c7321 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -4,6 +4,7 @@ using System.Data; using System.Data.SqlClient; using System.Linq; using System.Reflection; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -114,5 +115,20 @@ namespace SqlSugar return Convert.ToInt64(string.Join("", bytes).PadRight(20, '0')); } + internal static string GetMD5(string myString) + { + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); + byte[] targetData = md5.ComputeHash(fromData); + string byte2String = null; + + for (int i = 0; i < targetData.Length; i++) + { + byte2String += targetData[i].ToString("x"); + } + + return byte2String; + } + } }