From e090fee6de4f5e13884cbab97b0af0358deb27ff Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 11 Oct 2017 14:17:30 +0800 Subject: [PATCH] - --- Src/Asp.Net/ExtensionsDemo/CacheDemo.cs | 79 ++++++++++++++++++++----- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs b/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs index ca37357e4..cc6ba1880 100644 --- a/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs +++ b/Src/Asp.Net/ExtensionsDemo/CacheDemo.cs @@ -11,28 +11,36 @@ namespace ExtensionsDemo public class CacheDemo { public static void Init() + { + HttpRuntimeCache(); + //RedisCache(); + + } + + private static void HttpRuntimeCache() { ICacheService myCache = new HttpRuntimeCache();//ICacheService - SqlSugarClient db = new SqlSugarClient( new ConnectionConfig(){ - ConnectionString = Config.ConnectionString, - DbType = DbType.SqlServer, - IsAutoCloseConnection = true, - ConfigureExternalServices = new ConfigureExternalServices() - { - DataInfoCacheService = myCache //Setting external cache service - } - }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = Config.ConnectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = true, + ConfigureExternalServices = new ConfigureExternalServices() + { + DataInfoCacheService = myCache //Setting external cache service + } + }); + - for (int i = 0; i < 10000; i++) { db.Queryable().Where(it => it.Id > 0).WithCache().ToList(); } - db.Queryable((s1, s2) => s1.Id == s2.Id).Select(s1=>s1).WithCache().ToList(); + db.Queryable((s1, s2) => s1.Id == s2.Id).Select(s1 => s1).WithCache().ToList(); db.Queryable((s1, s2) => new object[] { @@ -40,19 +48,60 @@ namespace ExtensionsDemo }).Select(s1 => s1).WithCache().ToList(); - Console.WriteLine("Cache Key Count:"+myCache.GetAllKey().Count()); - + Console.WriteLine("Cache Key Count:" + myCache.GetAllKey().Count()); + foreach (var item in myCache.GetAllKey()) { Console.WriteLine(); Console.WriteLine(item); Console.WriteLine(); } - + + db.Deleteable().Where(it => it.Id == 1).RemoveDataCache().ExecuteCommand(); + + Console.WriteLine("Cache Key Count:" + myCache.GetAllKey().Count()); + } + private static void RedisCache() + { + ICacheService myCache = new RedisCache("localhost");//ICacheService + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = Config.ConnectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = true, + ConfigureExternalServices = new ConfigureExternalServices() + { + DataInfoCacheService = myCache //Setting external cache service + } + }); + + + for (int i = 0; i < 10000; i++) + { + db.Queryable().Where(it => it.Id > 0).WithCache().ToList(); + } + + + db.Queryable((s1, s2) => s1.Id == s2.Id).Select(s1 => s1).WithCache().ToList(); + + + db.Queryable((s1, s2) => new object[] { + JoinType.Left,s1.Id==s2.Id + }).Select(s1 => s1).WithCache().ToList(); + + + Console.WriteLine("Cache Key Count:" + myCache.GetAllKey().Count()); + + foreach (var item in myCache.GetAllKey()) + { + Console.WriteLine(); + Console.WriteLine(item); + Console.WriteLine(); + } + db.Deleteable().Where(it => it.Id == 1).RemoveDataCache().ExecuteCommand(); Console.WriteLine("Cache Key Count:" + myCache.GetAllKey().Count()); } - } }