Skip to content

Commit e3ee41e

Browse files
author
Kelly Yin
committed
Update DefaultHybridCache constructor to support DI localCache and backendCache
1 parent d5aa457 commit e3ee41e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Libraries/Microsoft.Extensions.Caching.Hybrid/Internal/DefaultHybridCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ internal enum CacheFeatures
6464

6565
internal bool HasBackendCache => (_features & CacheFeatures.BackendCache) != 0;
6666

67-
public DefaultHybridCache(IOptions<HybridCacheOptions> options, IServiceProvider services)
67+
public DefaultHybridCache(IOptions<HybridCacheOptions> options, IServiceProvider services, IMemoryCache? localCache = null, IDistributedCache ? backendCache = null)
6868
{
6969
_services = Throw.IfNull(services);
70-
_localCache = services.GetRequiredService<IMemoryCache>();
70+
_localCache = localCache ?? services.GetRequiredService<IMemoryCache>();
7171
_options = options.Value;
7272
_logger = services.GetService<ILoggerFactory>()?.CreateLogger(typeof(HybridCache)) ?? NullLogger.Instance;
7373
_clock = services.GetService<TimeProvider>() ?? TimeProvider.System;
74-
_backendCache = services.GetService<IDistributedCache>(); // note optional
74+
_backendCache = backendCache ?? services.GetService<IDistributedCache>(); // note optional
7575

7676
// ignore L2 if it is really just the same L1, wrapped
7777
// (note not just an "is" test; if someone has a custom subclass, who knows what it does?)

0 commit comments

Comments
 (0)