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;
///
/// 缓存管理
///
//[Authorize(Permissions.Name)]
[ApiExplorerSettings(GroupName = ApiGroupNameConst.System)]
public class CacheManageController : BaseApiController
{
private readonly ICaching _caching;
public CacheManageController(ICaching caching)
{
_caching = caching;
}
///
/// 获取全部缓存
///
///
[HttpGet]
public async Task>> Get()
{
return Success(await _caching.GetAllCacheKeysAsync());
}
///
/// 获取缓存
///
///
[HttpGet("{key}")]
public async Task> Get(string key)
{
return Success(await _caching.GetStringAsync(key));
}
///
/// 新增
///
///
[HttpPost]
public async Task 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();
}
///
/// 删除全部缓存
///
///
[HttpDelete]
public async Task Delete()
{
await _caching.RemoveAllAsync();
return SuccessMsg();
}
///
/// 删除缓存
///
///
[Route("{key}")]
[HttpDelete]
public async Task Delete(string key)
{
await _caching.RemoveAsync(key);
return SuccessMsg();
}
}