C# 使用IDistributedCache列出并删除给定组中的所有缓存项
我将用户生成的一些密钥存储在C# 使用IDistributedCache列出并删除给定组中的所有缓存项,c#,redis,asp.net-core-2.2,.net-4.7.2,C#,Redis,Asp.net Core 2.2,.net 4.7.2,我将用户生成的一些密钥存储在IDistributedCache设置中 密钥的使用期限很长,如果用户知道其中的每一个密钥,则可以由用户手动撤销: public void ConfigureServices(IServiceCollection services) { services.AddDistributedMemoryCache(); //... } //ControllerBase: //Adding the key: await _cache.SetAsync(use
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);
现在,我想做的是能够列出缓存中仍然存在的由其中一个用户创建的所有密钥。此外,我希望能够批量删除它们
现在有这样的功能吗?
也许用取消代币?如何操作?不,使用
IDistributedCache
一次只能使用一个键。大规模密钥收回和类似场景超出了此外观的范围。如果需要处理更高级的场景,那么应该使用适当的客户端直接连接到缓存。例如,对于Redis备份,您可以使用StackExchange.Redis
包,并通过该包发出您喜欢的任何命令