MemoryCacheServiceCollectionExtensions.AddDistributedMemoryCache 方法

定義

多載

AddDistributedMemoryCache(IServiceCollection)

新增 IDistributedCache 的預設實作,將記憶體中的項目儲存至 IServiceCollectionAdds a default implementation of IDistributedCache that stores items in memory to the IServiceCollection. 需要分散式快取才能運作的架構,可以安全地將此相依性新增為其相依性清單的一部分,以確保至少有一個可用的實作。Frameworks that require a distributed cache to work can safely add this dependency as part of their dependency list to ensure that there is at least one implementation available.

AddDistributedMemoryCache(IServiceCollection, Action<MemoryDistributedCacheOptions>)

新增 IDistributedCache 的預設實作,將記憶體中的項目儲存至 IServiceCollectionAdds a default implementation of IDistributedCache that stores items in memory to the IServiceCollection. 需要分散式快取才能運作的架構,可以安全地將此相依性新增為其相依性清單的一部分,以確保至少有一個可用的實作。Frameworks that require a distributed cache to work can safely add this dependency as part of their dependency list to ensure that there is at least one implementation available.

AddDistributedMemoryCache(IServiceCollection)

新增 IDistributedCache 的預設實作,將記憶體中的項目儲存至 IServiceCollectionAdds a default implementation of IDistributedCache that stores items in memory to the IServiceCollection. 需要分散式快取才能運作的架構,可以安全地將此相依性新增為其相依性清單的一部分,以確保至少有一個可用的實作。Frameworks that require a distributed cache to work can safely add this dependency as part of their dependency list to ensure that there is at least one implementation available.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddDistributedMemoryCache(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDistributedMemoryCache (this Microsoft.Extensions.DependencyInjection.IServiceCollection services);
static member AddDistributedMemoryCache : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddDistributedMemoryCache (services As IServiceCollection) As IServiceCollection

參數

services
IServiceCollection

要新增服務的 IServiceCollectionThe IServiceCollection to add services to.

傳回

IServiceCollection,讓其他呼叫可以進行鏈結。The IServiceCollection so that additional calls can be chained.

備註

AddDistributedMemoryCache(IServiceCollection) 只應在單一伺服器案例中使用,因為此快取會將專案儲存在記憶體中,而且不會跨越多部電腦擴充。AddDistributedMemoryCache(IServiceCollection) should only be used in single server scenarios as this cache stores items in memory and doesn't expand across multiple machines. 在這些情況下,建議使用可跨多部電腦擴充的適當分散式快取。For those scenarios it is recommended to use a proper distributed cache that can expand across multiple machines.

AddDistributedMemoryCache(IServiceCollection, Action<MemoryDistributedCacheOptions>)

新增 IDistributedCache 的預設實作,將記憶體中的項目儲存至 IServiceCollectionAdds a default implementation of IDistributedCache that stores items in memory to the IServiceCollection. 需要分散式快取才能運作的架構,可以安全地將此相依性新增為其相依性清單的一部分,以確保至少有一個可用的實作。Frameworks that require a distributed cache to work can safely add this dependency as part of their dependency list to ensure that there is at least one implementation available.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddDistributedMemoryCache(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Action<Microsoft::Extensions::Caching::Memory::MemoryDistributedCacheOptions ^> ^ setupAction);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDistributedMemoryCache (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.Extensions.Caching.Memory.MemoryDistributedCacheOptions> setupAction);
static member AddDistributedMemoryCache : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.Extensions.Caching.Memory.MemoryDistributedCacheOptions> -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddDistributedMemoryCache (services As IServiceCollection, setupAction As Action(Of MemoryDistributedCacheOptions)) As IServiceCollection

參數

services
IServiceCollection

要新增服務的 IServiceCollectionThe IServiceCollection to add services to.

setupAction
Action<MemoryDistributedCacheOptions>

用於設定所提供 MemoryDistributedCacheOptionsAction<T>The Action<T> to configure the provided MemoryDistributedCacheOptions.

傳回

IServiceCollection,讓其他呼叫可以進行鏈結。The IServiceCollection so that additional calls can be chained.

備註

AddDistributedMemoryCache(IServiceCollection) 只應在單一伺服器案例中使用,因為此快取會將專案儲存在記憶體中,而且不會跨越多部電腦擴充。AddDistributedMemoryCache(IServiceCollection) should only be used in single server scenarios as this cache stores items in memory and doesn't expand across multiple machines. 在這些情況下,建議使用可跨多部電腦擴充的適當分散式快取。For those scenarios it is recommended to use a proper distributed cache that can expand across multiple machines.

適用於