Nic*_*rin 6 c# redis .net-4.7.2 asp.net-core-2.2
IDistributedCache我在设置中存储用户生成的一些密钥。
密钥的有效期很长,如果用户知道其中的每一个,则可以由用户手动撤销:
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
//...
}
//ControllerBase:
//Adding the key:
await _cache.SetAsync(userKey, userId, new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(10)
});
//Removing the key:
await _cache.RemoveAsync(key);
Run Code Online (Sandbox Code Playgroud)
现在,我想要做的是能够列出缓存中仍然存在的由其中一位用户创建的所有密钥。另外,我希望能够批量删除它们。
现在有这样的功能吗?也许有取消令牌?我怎样才能做到这一点?
不可以,您一次只能使用一个键IDistributedCache。大规模密钥驱逐和类似场景超出了此外观的范围。如果您需要处理更高级的场景,那么您应该使用适当的客户端直接连接到缓存。例如,对于 Redis 支持,您可以使用该StackExchange.Redis包,并通过该包发出您喜欢的任何命令。
| 归档时间: |
|
| 查看次数: |
5823 次 |
| 最近记录: |