LinKit.Caching 1.3.1

dotnet add package LinKit.Caching --version 1.3.1
                    
NuGet\Install-Package LinKit.Caching -Version 1.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LinKit.Caching" Version="1.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinKit.Caching" Version="1.3.1" />
                    
Directory.Packages.props
<PackageReference Include="LinKit.Caching" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LinKit.Caching --version 1.3.1
                    
#r "nuget: LinKit.Caching, 1.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LinKit.Caching@1.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LinKit.Caching&version=1.3.1
                    
Install as a Cake Addin
#tool nuget:?package=LinKit.Caching&version=1.3.1
                    
Install as a Cake Tool

LinKit.Caching

NuGet

LinKit.Caching provides ICacheProvider with a bounded in-memory implementation and a high-performance, 100% Native AOT-compatible two-level (L1 In-Memory + L2 Redis) hybrid cache provider using a lightweight RESP2 socket client.

Install

dotnet add package LinKit.Caching

Register Cache Providers

In-Memory Provider

builder.Services.AddLinKitCaching();

Hybrid (L1 In-Memory + L2 Redis) Provider

Configure Redis connection directly:

builder.Services.AddLinKitCaching(options =>
{
    options.Enabled = true;
    options.Host = "localhost";
    options.Port = 6379;
    options.DefaultTtl = TimeSpan.FromMinutes(10);
});

Or using explicit configuration:

builder.Services.AddLinKitRedisCaching(new LinKitRedisOptions
{
    Host = "localhost",
    Port = 6379,
    DefaultTtl = TimeSpan.FromMinutes(10)
});

Inject ICacheProvider where needed:

public sealed class ProductService(ICacheProvider cache, IProductRepository products)
{
    public ValueTask<Product?> GetAsync(Guid id, CancellationToken cancellationToken) =>
        cache.GetOrCreateAsync(
            $"product:{id:N}",
            ct => products.FindByIdAsync(id, ct),
            ttl: TimeSpan.FromMinutes(5),
            cancellationToken);
}

GetOrCreateAsync shares an in-flight factory for the same key in InMemoryCacheProvider. A caller's cancellation cancels that caller's wait, not the shared factory; the factory is invoked with CancellationToken.None. Ensure factories have their own bounded I/O timeouts.

Direct operations

await cache.SetAsync(
    "catalog:featured",
    featuredProducts,
    ttl: TimeSpan.FromMinutes(10),
    sliding: TimeSpan.FromMinutes(2),
    cancellationToken);

var cached = await cache.GetAsync<List<Product>>("catalog:featured", cancellationToken);
await cache.RemoveAsync("catalog:featured", cancellationToken);

Use stable, namespaced keys and avoid putting secrets or raw personal data in cache keys. In-memory entries are process-local and are not shared between application instances. Capacity/LRU eviction is best-effort under concurrent writes; it is not a distributed cache or strict memory quota.

Implement a distributed provider

Implement ICacheProvider and register the implementation after AddLinKitCaching, or register only your provider:

builder.Services.AddSingleton<ICacheProvider, RedisCacheProvider>();

The interface includes GetAsync, SetAsync, RemoveAsync, and a default GetOrCreateAsync. The default method does not guarantee single-flight across concurrent callers; implement provider-specific coordination if that behavior is required. ICacheKeyResolver<TRequest> is a contract for a typed key resolver and must be implemented/registered by the application when used; this package does not currently generate cache-key resolvers.

[CacheAside] and [InvalidateCache] are metadata attributes only today; they do not add caching or invalidation behavior. The source generator reports LKM003 when either attribute is used. Call ICacheProvider.GetOrCreateAsync and RemoveAsync explicitly until generated handling is available.

Native AOT

The in-memory provider uses statically typed generic APIs and does not require runtime type discovery for its core operations. Validate the complete application, serializers, distributed provider, and dependencies with the target RID and AOT analyzers before claiming AOT compatibility.

License

MIT. See the repository license.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.1 48 10/31/2026
1.3.0 42 10/30/2026
1.2.0 71 10/29/2026
1.1.0 79 10/22/2026
1.0.0 82 10/20/2026