You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/RfidWeb/Tool/UserManager.cs

46 lines
966 B
C#

1 month ago
using NewLife.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DB.Dto;
3 weeks ago
using Tool.Model;
1 month ago
namespace RfidWeb
{
/// <summary>
/// 因为用户只有一个所有key是固定的
/// </summary>
public static class UserManager
{
2 weeks ago
private static string key => CacheKeyManager.HmiUser;
1 month ago
private static ICache cache = Cache.Default;
public static void Add(UserDto dto)
{
2 weeks ago
cache.Set(key, dto, TimeSpan.FromDays(2));
1 month ago
}
public static UserDto GetUser()
{
return cache.Get<UserDto>(key);
}
public static bool IsExit()
{
return cache.ContainsKey(key);
}
public static void RestoreTime()
{
if (IsExit())
{
2 weeks ago
cache.SetExpire(key, TimeSpan.FromDays(2));
1 month ago
}
}
}
}