From c2e3c29b70eee202f24f927d0b28e2812273f7c7 Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Mon, 10 Oct 2022 18:20:51 +0800
Subject: [PATCH] =?UTF-8?q?Redis=E7=BC=93=E5=86=B2=E6=9C=80=E5=A4=A724?=
=?UTF-8?q?=E5=B0=8F=E6=97=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DatabaseDefinitions/Cache/SqlSugarRedisCache.cs | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/Falcon.SugarApi/DatabaseDefinitions/Cache/SqlSugarRedisCache.cs b/Falcon.SugarApi/DatabaseDefinitions/Cache/SqlSugarRedisCache.cs
index e065b9a..552a77e 100644
--- a/Falcon.SugarApi/DatabaseDefinitions/Cache/SqlSugarRedisCache.cs
+++ b/Falcon.SugarApi/DatabaseDefinitions/Cache/SqlSugarRedisCache.cs
@@ -21,6 +21,11 @@ namespace Falcon.SugarApi.DatabaseDefinitions.Cache
///
public static SugarRedisClient Service { get; private set; } = null;
+ ///
+ /// 默认缓冲时间
+ ///
+ public const int DefaultcacheDurationInSeconds = 24 * 60 * 60;
+
///
/// 通过配置实现Redis缓冲,必须单例实现.
/// 默认:127.0.0.1:6379,password=,connectTimeout=3000,connectRetry=1,syncTimeout=10000,DefaultDatabase=0
@@ -43,7 +48,8 @@ namespace Falcon.SugarApi.DatabaseDefinitions.Cache
}
public void Add(string key, V value, int cacheDurationInSeconds) {
- Service.Set(key, value, cacheDurationInSeconds);
+ cacheDurationInSeconds = Math.Min(cacheDurationInSeconds, DefaultcacheDurationInSeconds);
+ Service.Set(key, value, cacheDurationInSeconds / 60);
}
public bool ContainsKey(string key) {
@@ -59,7 +65,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions.Cache
return Service.SearchCacheRegex("SqlSugarDataCache.*");
}
- public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = int.MaxValue) {
+ public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = DefaultcacheDurationInSeconds) {
if (ContainsKey(cacheKey)) {
var result = Get(cacheKey);
if (result == null) {