This commit is contained in:
sunkaixuan 2017-10-11 11:15:54 +08:00
parent d9f04041b8
commit eb87fbb500
2 changed files with 5 additions and 2 deletions

View File

@ -11,7 +11,8 @@ namespace ExtensionsDemo
{
public static void Init()
{
var myCache = new SqlSugar.Extensions.HttpRuntimeCache();
ICacheService myCache = new SqlSugar.Extensions.HttpRuntimeCache();//ICacheService
SqlSugarClient db = new SqlSugarClient(
new ConnectionConfig()
{
@ -20,7 +21,7 @@ namespace ExtensionsDemo
IsAutoCloseConnection = true,
ConfigureExternalServices = new ConfigureExternalServices()
{
DataInfoCacheService = myCache
DataInfoCacheService = myCache //Setting external cache service
}
});
@ -35,6 +36,7 @@ namespace ExtensionsDemo
JoinType.Left,s1.Id==s2.Id
}).Select(s1 => s1).WithCache().ToList();
Console.WriteLine("Cache Key Count:"+myCache.GetAllKey<string>().Count());
foreach (var item in myCache.GetAllKey<string>())
{

View File

@ -600,6 +600,7 @@ namespace SqlSugar
}
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
Check.ArgumentNullException(this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService, "Use Cache ConnectionConfig.ConfigureExternalServices.DataInfoCacheService is required ");
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;