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.
81 lines
1.8 KiB
C#
81 lines
1.8 KiB
C#
using EntrustSettle.Common.Caches;
|
|
using EntrustSettle.Common.Const;
|
|
using EntrustSettle.Controllers;
|
|
using EntrustSettle.Model;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EntrustSettle.Api.Controllers.Systems;
|
|
|
|
/// <summary>
|
|
/// 缓存管理
|
|
/// </summary>
|
|
//[Authorize(Permissions.Name)]
|
|
[ApiExplorerSettings(GroupName = ApiGroupNameConst.System)]
|
|
public class CacheManageController : BaseApiController
|
|
{
|
|
private readonly ICaching _caching;
|
|
|
|
public CacheManageController(ICaching caching)
|
|
{
|
|
_caching = caching;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取全部缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<MessageModel<List<string>>> Get()
|
|
{
|
|
return Success(await _caching.GetAllCacheKeysAsync());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("{key}")]
|
|
public async Task<MessageModel<string>> Get(string key)
|
|
{
|
|
return Success<string>(await _caching.GetStringAsync(key));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<MessageModel> Post([FromQuery] string key, [FromQuery] string value, [FromQuery] int? expire)
|
|
{
|
|
if (expire.HasValue)
|
|
await _caching.SetStringAsync(key, value, TimeSpan.FromMilliseconds(expire.Value));
|
|
else
|
|
await _caching.SetStringAsync(key, value);
|
|
|
|
return SuccessMsg();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除全部缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpDelete]
|
|
public async Task<MessageModel> Delete()
|
|
{
|
|
await _caching.RemoveAllAsync();
|
|
return SuccessMsg();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("{key}")]
|
|
[HttpDelete]
|
|
public async Task<MessageModel> Delete(string key)
|
|
{
|
|
await _caching.RemoveAsync(key);
|
|
return SuccessMsg();
|
|
}
|
|
} |