diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index c89097ffe..b6eed3cd3 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -778,13 +778,16 @@ namespace SqlSugar } public ISugarQueryable 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 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 WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (isCache) { this.IsCache = true; @@ -2281,12 +2295,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -2708,12 +2724,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -3062,12 +3080,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -3447,12 +3467,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -3863,12 +3885,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -4312,12 +4336,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -4710,12 +4736,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; @@ -5119,12 +5147,14 @@ namespace SqlSugar } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { + cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable