using Furion;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using GDZZ.Application.Enum;
using GDZZ.Core;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GDZZ.Application.Help
{
///
/// 系统缓存服务
///
public class CacheService : ICacheService, IDynamicApiController, ITransient
{
private static ICache _redisCache = App.RootServices.GetService(typeof(RedisCache)) as ICache;
///
///
///
public CacheService() { }
#region 聊天服务
///
/// 获取聊天列表
///
///
[NonAction]
public async Task> GetLiveHistoryService(long UserID)
{
string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}";
return await _redisCache.GetAsync>(cacheKey);
}
///
/// 设置聊天列表
///
///
[NonAction]
public async Task SetLiveHistoryService(long UserID, List liveMessageLists)
{
string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}";
await _redisCache.SetAsync(cacheKey, liveMessageLists, TimeSpan.FromHours(1));
}
///
/// 删除聊天列表
///
///
[NonAction]
public async Task DelLiveHistoryService(long UserID)
{
string cacheKey = SystemConst.LIVE_HISTORYLIST + $"{UserID}";
await _redisCache.DelAsync(cacheKey);
}
#endregion
#region 聊天详情
///
/// 获取聊天列表
///
///
[NonAction]
public async Task> GetMessage(long UserID,long ChatUserID)
{
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
return await _redisCache.GetAsync>(cacheKey);
}
///
/// 获取聊天列表
///
///
[NonAction]
public async Task SetMessage(List liveMessages,long UserID,long ChatUserID)
{
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
await _redisCache.SetAsync(cacheKey, liveMessages, TimeSpan.FromHours(1));
}
///
/// 获取聊天列表
///
///
[NonAction]
public async Task DelMessage(long UserID, long ChatUserID)
{
string cacheKey = SystemConst.LIVE_MESSAGE + $"{UserID}_{ChatUserID}";
await _redisCache.DelAsync(cacheKey);
}
#endregion
}
}