在ASP.NET的Core 2我們可以添加一個Azure的Redis的緩存是這樣的:ASP.NET睿2 - 多Azure的Redis的緩存服務DI
services.AddDistributedRedisCache(config =>
{
config.Configuration = Configuration.GetConnectionString("RedisCacheConnection");
config.InstanceName = "MYINSTANCE";
});
然後使用將是這樣的:
private readonly IDistributedCache _cache;
public MyController(IDistributedCache cache)
{
_cache = cache;
}
我怎麼能做到這一點,讓我有:
private readonly IDistributedCache _cache1;
private readonly IDistributedCache _cache2;
public MyController(IDistributedCache cache1, IDistributedCache cache2)
{
_cache1 = cache1;
_cache2 = cache2;
}
我的問題,我怎麼能添加指向不同的Redis Azure的另一個緩存服務當我想要使用它們時,連接和實例並將它們分開?
這種先進的方案是不使用默認的'IDistributedCache'做法確實管理。您應該使用像[CacheManager](http://cachemanager.michaco.net/)這樣的庫,它允許您根據類型參數定義不同的緩存。 –
一個潛在的選擇是使用[策略模式](https://stackoverflow.com/a/46597099)來選擇要在運行時使用的緩存。 – NightOwl888