将db缓存改成系统自带
This commit is contained in:
parent
bf296c88ea
commit
90ae95536f
@ -1,4 +1,5 @@
|
||||
using ZR.Common.Cache;
|
||||
using ZR.Common;
|
||||
using ZR.Common.Cache;
|
||||
|
||||
namespace ZR.Admin.WebApi.Extensions
|
||||
{
|
||||
@ -6,22 +7,26 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
{
|
||||
public void Add<V>(string key, V value)
|
||||
{
|
||||
RedisServer.Cache.Set(key, value, 3600 + RedisHelper.RandomExpired(5, 30));
|
||||
//RedisServer.Cache.Set(key, value, 3600 + RedisHelper.RandomExpired(5, 30));
|
||||
CacheHelper.SetCache(key, value);
|
||||
}
|
||||
|
||||
public void Add<V>(string key, V value, int cacheDurationInSeconds)
|
||||
{
|
||||
RedisServer.Cache.Set(key, value, cacheDurationInSeconds);
|
||||
//RedisServer.Cache.Set(key, value, cacheDurationInSeconds);
|
||||
CacheHelper.SetCaches(key, value, cacheDurationInSeconds);
|
||||
}
|
||||
|
||||
public bool ContainsKey<V>(string key)
|
||||
{
|
||||
return RedisServer.Cache.Exists(key);
|
||||
//return RedisServer.Cache.Exists(key);
|
||||
return CacheHelper.Exists(key);
|
||||
}
|
||||
|
||||
public V Get<V>(string key)
|
||||
{
|
||||
return RedisServer.Cache.Get<V>(key);
|
||||
//return RedisServer.Cache.Get<V>(key);
|
||||
return (V)CacheHelper.Get(key);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllKey<V>()
|
||||
|
||||
@ -106,6 +106,18 @@ namespace ZR.Common
|
||||
{
|
||||
Cache.Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证缓存项是否存在
|
||||
/// </summary>
|
||||
/// <param name="key">缓存Key</param>
|
||||
/// <returns></returns>
|
||||
public static bool Exists(string key)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
return Cache.TryGetValue(key, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user