namespace IStation.Service
|
{
|
/// <summary>
|
/// 缓存辅助类
|
/// </summary>
|
public class CacheHelper<T>
|
{
|
#region Default
|
|
// 查询缓存键
|
private static string GetCacheKey()
|
{
|
var t = typeof(T);
|
return CacheKeyHelper.GetCacheKey(t.Name);
|
}
|
|
/// <summary>
|
/// 设置缓存
|
/// </summary>
|
public static void Set(List<T> list, int minutes = 30, int randomSeconds = 0)
|
{
|
var cacheKey = GetCacheKey();
|
MemoryCacheHelper.Set(cacheKey, list, minutes * 60 + randomSeconds);
|
}
|
|
/// <summary>
|
/// 查询缓存
|
/// </summary>
|
public static List<T> Get()
|
{
|
var cacheKey = GetCacheKey();
|
return MemoryCacheHelper.Get<List<T>>(cacheKey);
|
}
|
|
/// <summary>
|
/// 查询设置缓存
|
/// </summary>
|
public static List<T> GetSet(Func<List<T>> func, int minutes = 30, int randomSeconds = 0)
|
{
|
var cacheKey = GetCacheKey();
|
return MemoryCacheHelper.GetSet(cacheKey, func, minutes * 60 + randomSeconds);
|
}
|
|
/// <summary>
|
/// 移除缓存
|
/// </summary>
|
public static void Remove()
|
{
|
var cacheKey = GetCacheKey();
|
MemoryCacheHelper.Remove(cacheKey);
|
}
|
|
/// <summary>
|
/// 发布
|
/// </summary>
|
public static void Publish(string Key)
|
{
|
var cacheKey = GetCacheKey();
|
MemoryCacheWipeRelationHelper.Set(Key, cacheKey);
|
}
|
|
/// <summary>
|
/// 触发
|
/// </summary>
|
public static void Trigger()
|
{
|
var cacheKey = GetCacheKey();
|
MemoryCacheWipeRelationHelper.Trigger(cacheKey);
|
}
|
|
#endregion
|
}
|
}
|