DotNetXtensions.DCache
v3.0.4Latest Stable
net8.0
Provides cached dictionary types: - `CacheDictionary`: an in-memory cache dictionary whose items auto-expire after set timespan - `DCache`: an implementation of `IDistributedCache` that abstracts the distributed-cache logic, functioning like a simple typed dictionary
Published
Feb 27, 2026
8mo ago
Total Downloads
3.9K
3,874
Install
dotnet add package DotNetXtensions.DCache --version 3.0.4
| Product | Versions |
|---|---|
| .NET |
README
DotNetXtensions.DCache
High-performance caching types for .NET 8+
- CacheDictionary: Thread-safe in-memory cache dictionary with automatic time-based expiration
- DCache: Allows an IDistributedCache to look and act like a simple in-memory typed dictionary, with dual-layer caching
Installation
dotnet add package DotNetXtensions.DCache
CacheDictionary
// Items auto-expire after 5 minutes
CacheDictionary<string, User> cache = new(TimeSpan.FromMinutes(5));
cache["user123"] = new User { Name = "Alice" };
if (cache.TryGetValue("user123", out User user))
WriteLine(user.Name);
Features
- Time-Based Expiration: Items automatically expire after a set duration
- Thread-Safe: Built on
ConcurrentDictionaryfor safe concurrent access - High Performance: Minimal overhead on normal Get/Set operations
- Passive Purging: Expired items are removed intelligently without requiring external timers
- Guaranteed Fresh Data: Expired items are never returned, even if still present internally
- Automatic Disposal: Optional automatic disposal of
IDisposablecached values
DCache
// Combines L1 (memory) + L2 (distributed) caching
DCache<User, string> cache = new(distributedCache);
await cache.SetAsync("user123", user);
User retrieved = await cache.GetAsync("user123");
Features
- Simplicity: With little effort or boilerplate, an
IDistributedCachelooks and acts like a simple in-memory typed dictionary - Dual-Layer Caching: Combines fast (optional) in-memory caching (L1) with distributed caching (L2) for optimal performance
- Automatic Serialization: Handles JSON serialization/deserialization transparently using
System.Text.Json - Simplified API: Reduces boilerplate code for common caching patterns with typed keys and values
When to Use Which?
| Use CacheDictionary when... | Use DCache when... |
|---|---|
| Single-server scenarios | Multi-server/distributed systems |
| You need time-based expiration | You're already using IDistributedCache |
| Synchronous access is preferred | You need Redis, SQL Server, or other distributed caches |
| Memory-only caching is sufficient | You want L1 + L2 caching optimization |
Changes from Previous Version
v2.0.0v3.0.4
Added Frameworks
net8.0
Removed Frameworks
net6.0
Added Dependencies
Removed Dependencies
DotNetXtensions.Common(net6.0)
DotNetXtensions(net6.0)
Deprecation Removed
Deprecation notice was removed in this version.Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.