1 interface inheriting from IDistributedCache
Microsoft.Extensions.Caching.Abstractions (1)
IBufferDistributedCache.cs (1)
13public interface IBufferDistributedCache : IDistributedCache
4 implementations of IDistributedCache
Microsoft.AspNetCore.Session.Tests (1)
SessionTests.cs (1)
1145private class UnreliableCache : IDistributedCache
Microsoft.Extensions.Caching.Hybrid.Tests (1)
StampedeTests.cs (1)
32public sealed class InvalidCache : IDistributedCache, IMemoryCache
Microsoft.Extensions.Caching.Memory (1)
MemoryDistributedCache.cs (1)
17public class MemoryDistributedCache : IDistributedCache
Microsoft.Extensions.Caching.SqlServer (1)
SqlServerCache.cs (1)
19public class SqlServerCache : IDistributedCache, IBufferDistributedCache
173 references to IDistributedCache
Aspire.StackExchange.Redis.DistributedCaching (2)
AspireRedisDistributedCacheExtensions.cs (2)
18/// Adds Redis distributed caching services, <see cref="IDistributedCache"/>, in the services provided by the <paramref name="builder"/>. 41/// Adds Redis distributed caching services, <see cref="IDistributedCache"/>, in the services provided by the <paramref name="builder"/>.
Aspire.StackExchange.Redis.DistributedCaching.Tests (4)
AspireRedisDistributedCacheExtensionsTests.cs (2)
22var cache = host.Services.GetRequiredService<IDistributedCache>();
DistributedCacheConformanceTests.cs (2)
62var cache = host.Services.GetRequiredService<IDistributedCache>();
Aspire.StackExchange.Redis.Tests (4)
AspireRedisExtensionsTests.cs (4)
226var distributedCache = host.Services.GetRequiredService<IDistributedCache>(); 358var distributedCache = host.Services.GetRequiredService<IDistributedCache>();
Microsoft.Analyzers.Local.Tests (1)
ApiLifecycle\ApiLifecycleAnalyzerTest.cs (1)
92Assembly.GetAssembly(typeof(IDistributedCache))!,
Microsoft.AspNetCore.Mvc.TagHelpers (4)
Cache\DistributedCacheTagHelperStorage.cs (4)
10/// in using <see cref="IDistributedCache"/> as the store. 14private readonly IDistributedCache _distributedCache; 19/// <param name="distributedCache">The <see cref="IDistributedCache"/> to use.</param> 20public DistributedCacheTagHelperStorage(IDistributedCache distributedCache)
Microsoft.AspNetCore.Session (8)
DistributedSession.cs (4)
15/// An <see cref="ISession"/> backed by an <see cref="IDistributedCache"/>. 26private readonly IDistributedCache _cache; 43/// <param name="cache">The <see cref="IDistributedCache"/> used to store the session data.</param> 58IDistributedCache cache,
DistributedSessionStore.cs (4)
11/// An <see cref="ISessionStore"/> backed by an <see cref="IDistributedCache"/>. 15private readonly IDistributedCache _cache; 21/// <param name="cache">The <see cref="IDistributedCache"/> used to store the session data.</param> 23public DistributedSessionStore(IDistributedCache cache, ILoggerFactory loggerFactory)
Microsoft.AspNetCore.Session.Tests (9)
SessionTests.cs (9)
664services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 713services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 762services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 810services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 862services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 925services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 991services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 1056services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions())) 1108services.AddSingleton<IDistributedCache>(new UnreliableCache(new MemoryCache(new MemoryCacheOptions()))
Microsoft.Extensions.Caching.Abstractions (15)
DistributedCacheEntryOptions.cs (1)
9/// Provides the cache options for an entry in <see cref="IDistributedCache"/>.
DistributedCacheExtensions.cs (9)
12/// Extension methods for setting data in an <see cref="IDistributedCache" />. 23public static void Set(this IDistributedCache cache, string key, byte[] value) 40public static Task SetAsync(this IDistributedCache cache, string key, byte[] value, CancellationToken token = default(CancellationToken)) 55public static void SetString(this IDistributedCache cache, string key, string value) 68public static void SetString(this IDistributedCache cache, string key, string value, DistributedCacheEntryOptions options) 85public static Task SetStringAsync(this IDistributedCache cache, string key, string value, CancellationToken token = default(CancellationToken)) 100public static Task SetStringAsync(this IDistributedCache cache, string key, string value, DistributedCacheEntryOptions options, CancellationToken token = default(CancellationToken)) 114public static string? GetString(this IDistributedCache cache, string key) 131public static async Task<string?> GetStringAsync(this IDistributedCache cache, string key, CancellationToken token = default(CancellationToken))
Hybrid\HybridCache.cs (1)
15/// Provides multi-tier caching services building on <see cref="IDistributedCache"/> backends.
IBufferDistributedCache.cs (4)
21/// <remarks>This method is functionally similar to <see cref="IDistributedCache.Get(string)"/>, but avoids the array allocation.</remarks> 31/// <remarks>This method is functionally similar to <see cref="IDistributedCache.GetAsync(string, CancellationToken)"/>, but avoids the array allocation.</remarks> 40/// <remarks>This method is functionally similar to <see cref="IDistributedCache.Set(string, byte[], DistributedCacheEntryOptions)"/>, but avoids the array allocation.</remarks> 50/// <remarks>This method is functionally similar to <see cref="IDistributedCache.SetAsync(string, byte[], DistributedCacheEntryOptions, CancellationToken)"/>, but avoids the array allocation.</remarks>
Microsoft.Extensions.Caching.Hybrid (3)
Internal\DefaultHybridCache.cs (3)
26private readonly IDistributedCache? _backendCache; 66_backendCache = services.GetService<IDistributedCache>(); // note optional 107internal IDistributedCache? BackendCache => _backendCache;
Microsoft.Extensions.Caching.Hybrid.Tests (34)
BufferReleaseTests.cs (2)
113services => services.AddSingleton<IDistributedCache, TestCache>()); 174services => services.AddSingleton<IDistributedCache, TestCache>());
DistributedCacheTests.cs (6)
60var cache = (await InitAsync()).BuildServiceProvider().GetService<IDistributedCache>(); 106var cache = (await InitAsync()).BuildServiceProvider().GetService<IDistributedCache>(); 172var cache = (await InitAsync()).BuildServiceProvider().GetService<IDistributedCache>() as IBufferDistributedCache; 234var cache = (await InitAsync()).BuildServiceProvider().GetService<IDistributedCache>() as IBufferDistributedCache;
L2Tests.cs (13)
39services.AddSingleton<IDistributedCache>(buffers ? new BufferLoggingCache(Log, localCache) : new LoggingCache(Log, localCache)); 159public BufferLoggingCache(ITestOutputHelper log, IDistributedCache tail) 207private class LoggingCache(ITestOutputHelper log, IDistributedCache tail) : IDistributedCache 210protected IDistributedCache Tail => tail; 216byte[]? IDistributedCache.Get(string key) 223Task<byte[]?> IDistributedCache.GetAsync(string key, CancellationToken token) 230void IDistributedCache.Refresh(string key) 237Task IDistributedCache.RefreshAsync(string key, CancellationToken token) 244void IDistributedCache.Remove(string key) 251Task IDistributedCache.RemoveAsync(string key, CancellationToken token) 258void IDistributedCache.Set(string key, byte[] value, DistributedCacheEntryOptions options) 265Task IDistributedCache.SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token)
SampleUsage.cs (1)
91public class SomeDCService(IDistributedCache cache)
ServiceConstructionTests.cs (3)
158services.AddSingleton<IDistributedCache, MemoryDistributedCache>(); 176services.AddSingleton<IDistributedCache, CustomMemoryDistributedCache>(); 192services.AddSingleton<IDistributedCache, MemoryDistributedCache>();
StampedeTests.cs (9)
18services.AddSingleton<IDistributedCache, InvalidCache>(); 41byte[]? IDistributedCache.Get(string key) => throw new NotSupportedException("Intentionally not provided"); 43Task<byte[]?> IDistributedCache.GetAsync(string key, CancellationToken token) => throw new NotSupportedException("Intentionally not provided"); 45void IDistributedCache.Refresh(string key) => throw new NotSupportedException("Intentionally not provided"); 47Task IDistributedCache.RefreshAsync(string key, CancellationToken token) => throw new NotSupportedException("Intentionally not provided"); 49void IDistributedCache.Remove(string key) => throw new NotSupportedException("Intentionally not provided"); 53Task IDistributedCache.RemoveAsync(string key, CancellationToken token) => throw new NotSupportedException("Intentionally not provided"); 55void IDistributedCache.Set(string key, byte[] value, DistributedCacheEntryOptions options) => throw new NotSupportedException("Intentionally not provided"); 57Task IDistributedCache.SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token) => throw new NotSupportedException("Intentionally not provided");
Microsoft.Extensions.Caching.Memory (4)
MemoryCacheServiceCollectionExtensions.cs (3)
53/// Adds a default implementation of <see cref="IDistributedCache"/> that stores items in memory 71services.TryAdd(ServiceDescriptor.Singleton<IDistributedCache, MemoryDistributedCache>()); 77/// Adds a default implementation of <see cref="IDistributedCache"/> that stores items in memory
MemoryDistributedCache.cs (1)
15/// Implements <see cref="IDistributedCache"/> using <see cref="IMemoryCache"/>.
Microsoft.Extensions.Caching.MicroBenchmarks (2)
DistributedCacheBenchmarks.cs (2)
58sqlServer = (IBufferDistributedCache)services.BuildServiceProvider().GetRequiredService<IDistributedCache>(); 66redis = (IBufferDistributedCache)services.BuildServiceProvider().GetRequiredService<IDistributedCache>();
Microsoft.Extensions.Caching.SqlServer (1)
SqlServerCachingServicesExtensions.cs (1)
37services.Add(ServiceDescriptor.Singleton<IDistributedCache, SqlServerCache>());
Microsoft.Extensions.Caching.SqlServer.Tests (29)
SqlServerCacheServicesExtensionsTest.cs (5)
25Assert.Equal(typeof(IDistributedCache), serviceDescriptor.ServiceType); 35services.AddScoped(typeof(IDistributedCache), sp => Mock.Of<IDistributedCache>()); 48var distributedCache = services.FirstOrDefault(desc => desc.ServiceType == typeof(IDistributedCache)); 52Assert.IsType<SqlServerCache>(serviceProvider.GetRequiredService<IDistributedCache>());
SqlServerCacheWithDatabaseTest.cs (24)
61var cache = GetSqlServerCache(); 78var cache = GetSqlServerCache(GetCacheOptions(testClock)); 100var cache = GetSqlServerCache(GetCacheOptions(testClock)); 128var cache = GetSqlServerCache(cacheOptions); 169var cache = GetSqlServerCache(cacheOptions); 209var cache = GetSqlServerCache(GetCacheOptions(testClock)); 232var cache = GetSqlServerCache(GetCacheOptions(testClock)); 258var cache = GetSqlServerCache(GetCacheOptions(testClock)); 290var cache = GetSqlServerCache(GetCacheOptions(testClock)); 315var cache = GetSqlServerCache(GetCacheOptions(testClock)); 338var cache = GetSqlServerCache(GetCacheOptions(testClock)); 363var cache = GetSqlServerCache(GetCacheOptions(testClock)); 392var cache = GetSqlServerCache(); 419var cache = GetSqlServerCache(GetCacheOptions(testClock)); 459var cache = GetSqlServerCache(GetCacheOptions(testClock)); 488var cache = GetSqlServerCache(GetCacheOptions(testClock)); 520var cache = GetSqlServerCache(GetCacheOptions(testClock)); 576var cache = GetSqlServerCache(GetCacheOptions(testClock)); 605var cache = GetSqlServerCache(GetCacheOptions(testClock)); 633var cache = GetSqlServerCache(); 652var cache = GetSqlServerCache(); 673var cache = GetSqlServerCache(); 687private IDistributedCache GetSqlServerCache(SqlServerCacheOptions options = null) 710IDistributedCache cache,
Microsoft.Extensions.Caching.StackExchangeRedis (1)
StackExchangeRedisCacheServiceCollectionExtensions.cs (1)
32services.Add(ServiceDescriptor.Singleton<IDistributedCache, RedisCacheImpl>());
Microsoft.Extensions.Caching.StackExchangeRedis.Tests (52)
CacheServiceExtensionsTests.cs (13)
26var distributedCache = services.FirstOrDefault(desc => desc.ServiceType == typeof(IDistributedCache)); 37services.AddScoped(typeof(IDistributedCache), sp => Mock.Of<IDistributedCache>()); 45var distributedCache = services.FirstOrDefault(desc => desc.ServiceType == typeof(IDistributedCache)); 49Assert.IsAssignableFrom<RedisCache>(serviceProvider.GetRequiredService<IDistributedCache>()); 71var distributedCache = serviceProvider.GetRequiredService<IDistributedCache>(); 88var distributedCache = serviceProvider.GetRequiredService<IDistributedCache>(); 98services.AddScoped(typeof(IDistributedCache), sp => Mock.Of<IDistributedCache>()); 116var distributedCache = services.FirstOrDefault(desc => desc.ServiceType == typeof(IDistributedCache)); 120Assert.IsAssignableFrom<RedisCache>(serviceProvider.GetRequiredService<IDistributedCache>());
Infrastructure\RedisTestConfig.cs (1)
24public static IDistributedCache CreateCacheInstance(string instanceName)
RedisCacheSetAndRemoveTests.cs (10)
22var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 32var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 45var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 62var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 79var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 95var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 105var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 119var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 136var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 159var cache = RedisTestConfig.CreateCacheInstance(GetType().Name);
TimeExpirationAsyncTests.cs (14)
40var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 58var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 79var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 92var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 108var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 124var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 144var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 157var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 170var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 186var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 204var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 217var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 242var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 272static async Task<string> GetNameAndReset(IDistributedCache cache, [CallerMemberName] string caller = "")
TimeExpirationTests.cs (14)
23var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 41var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 62var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 75var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 91var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 108var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 128var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 141var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 154var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 171var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 189var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 202var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 227var cache = RedisTestConfig.CreateCacheInstance(GetType().Name); 257static string GetNameAndReset(IDistributedCache cache, [CallerMemberName] string caller = "")