Browse Source

Add Config DefaultCacheDurationInSeconds

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
852d66ca8a
  1. 34
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 1
      Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs

34
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -778,13 +778,16 @@ namespace SqlSugar
}
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
Check.ArgumentNullException(this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService, "Use Cache ConnectionConfig.ConfigureExternalServices.DataInfoCacheService is required ");
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (isCache)
{
this.IsCache = true;
@ -1631,6 +1634,15 @@ namespace SqlSugar
asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos;
asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex;
}
protected int SetCacheTime(int cacheDurationInSeconds)
{
if (cacheDurationInSeconds == int.MaxValue && this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds > 0)
{
cacheDurationInSeconds = this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds;
}
return cacheDurationInSeconds;
}
#endregion
}
@ -1912,12 +1924,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (isCache)
{
this.IsCache = true;
@ -2281,12 +2295,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -2708,12 +2724,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -3062,12 +3080,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -3447,12 +3467,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -3863,12 +3885,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -4312,12 +4336,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -4710,12 +4736,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -5119,12 +5147,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -5552,12 +5582,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@ -6011,12 +6043,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;

1
Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs

@ -13,5 +13,6 @@ namespace SqlSugar
/// Some MYSQL databases do not support NVarchar set true
/// </summary>
public bool MySqlDisableNarvchar { get; set; }
public int DefaultCacheDurationInSeconds { get; set; }
}
}

Loading…
Cancel
Save