// Services.Cache.BaseCacheHelpRedis using System; using System.Collections.Generic; using Org.BouncyCastle.Utilities; using Services.Tool; using StackExchange.Redis; public abstract class BaseCacheHelpRedis { public static T GetCache(string key, Func setAcrion, TimeSpan? expiry = null) { if (RedisHelper.CheckKey(key)) { return RedisHelper.StringGet(key); } T val = setAcrion(); if (val != null) { RedisHelper.StringSet(key, val, expiry); } return val; } public static void SetCache(string key, Func setAcrion, TimeSpan? expiry = null) { T val = setAcrion(); if (val != null) { RedisHelper.StringSet(key, val, expiry); } } public static T GetVaue(string key) { if (RedisHelper.CheckKey(key)) { return RedisHelper.StringGet(key); } return default(T); } public static void ClearCache(string key) { if (RedisHelper.CheckKey(key)) { RedisHelper.RemoveKey(key); } } public static void ClearCacheList(List keyList) { RedisHelper.RemoveKeyList(keyList); } public static T GetHashCache(string key, string sid, Func setAcrion) { if (RedisHelper.HashExists(key, sid)) { return RedisHelper.HashGet(key, sid); } T val = setAcrion(); if (val != null) { RedisHelper.HashSet(key, sid, val); } return val; } public static void SetHashCache(string key, string sid, T model) { RedisHelper.HashSet(key, sid, model); } public static void SetHashCache(string key, Dictionary dic) { RedisHelper.HashSet(key, dic); } public static Dictionary GetHashAllCache(string key) { return RedisHelper.HashGetAll(key); } public static bool CheckKey(string key) { return RedisHelper.CheckKey(key); } }