Redis缓冲最大24小时
This commit is contained in:
parent
346ebc47c3
commit
c2e3c29b70
|
@ -21,6 +21,11 @@ namespace Falcon.SugarApi.DatabaseDefinitions.Cache
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static SugarRedisClient Service { get; private set; } = null;
|
public static SugarRedisClient Service { get; private set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认缓冲时间
|
||||||
|
/// </summary>
|
||||||
|
public const int DefaultcacheDurationInSeconds = 24 * 60 * 60;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过配置实现Redis缓冲,必须单例实现.
|
/// 通过配置实现Redis缓冲,必须单例实现.
|
||||||
/// <para>默认:127.0.0.1:6379,password=,connectTimeout=3000,connectRetry=1,syncTimeout=10000,DefaultDatabase=0</para>
|
/// <para>默认:127.0.0.1:6379,password=,connectTimeout=3000,connectRetry=1,syncTimeout=10000,DefaultDatabase=0</para>
|
||||||
|
@ -43,7 +48,8 @@ namespace Falcon.SugarApi.DatabaseDefinitions.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add<V>(string key, V value, int cacheDurationInSeconds) {
|
public void Add<V>(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<V>(string key) {
|
public bool ContainsKey<V>(string key) {
|
||||||
|
@ -59,7 +65,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions.Cache
|
||||||
return Service.SearchCacheRegex("SqlSugarDataCache.*");
|
return Service.SearchCacheRegex("SqlSugarDataCache.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
public V GetOrCreate<V>(string cacheKey, Func<V> create, int cacheDurationInSeconds = int.MaxValue) {
|
public V GetOrCreate<V>(string cacheKey, Func<V> create, int cacheDurationInSeconds = DefaultcacheDurationInSeconds) {
|
||||||
if (ContainsKey<V>(cacheKey)) {
|
if (ContainsKey<V>(cacheKey)) {
|
||||||
var result = Get<V>(cacheKey);
|
var result = Get<V>(cacheKey);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user