Skip to content

Providers

Aghogho Bernard edited this page May 6, 2026 · 1 revision

Providers

CacheWeave ships eight provider packages. Each registers against ICacheProviderInner — the core library wraps it transparently with optional compression.

Redis (CacheWeave.Redis)

dotnet add package CacheWeave.Redis
using CacheWeave.Redis.Extensions;

// Connection string
builder.Services.AddCacheWeaveRedis("localhost:6379");

// With SSL (Azure Cache for Redis)
builder.Services.AddCacheWeaveRedis(
    "my-cache.redis.cache.windows.net:6380,ssl=true,password=...,abortConnect=false");

// Reuse an existing IConnectionMultiplexer
builder.Services.AddSingleton<IConnectionMultiplexer>(
    _ => ConnectionMultiplexer.Connect("localhost:6379"));
builder.Services.AddCacheWeaveRedis(
    sp => sp.GetRequiredService<IConnectionMultiplexer>());

RemoveByPrefix: Supported via Redis SCAN + DEL. Safe for large keyspaces — scans and deletes in batches of 250.


InMemory (CacheWeave.InMemory)

dotnet add package CacheWeave.InMemory
using CacheWeave.InMemory.Extensions;

builder.Services.AddCacheWeaveInMemory();

// With custom MemoryCacheOptions
builder.Services.AddCacheWeaveInMemory(opts =>
{
    opts.SizeLimit = 1024; // max entries
});

RemoveByPrefix: Supported via in-process prefix scan.

Use this for development, testing, or single-instance deployments where distributed caching is not required.


DistributedCache (CacheWeave.DistributedCache)

dotnet add package CacheWeave.DistributedCache

Wraps any IDistributedCache implementation (e.g. Microsoft.Extensions.Caching.StackExchangeRedis, Microsoft.Extensions.Caching.SqlServer) so it can be used as a CacheWeave provider.

using CacheWeave.DistributedCache.Extensions;

// No prefix invalidation — IDistributedCache only
builder.Services.AddStackExchangeRedisCache(opts =>
    opts.Configuration = "localhost:6379");
builder.Services.AddCacheWeaveDistributedCache();

// With prefix invalidation via IConnectionMultiplexer (connection string)
builder.Services.AddCacheWeaveDistributedCache("localhost:6379");

// With prefix invalidation via an existing IConnectionMultiplexer
builder.Services.AddSingleton<IConnectionMultiplexer>(
    _ => ConnectionMultiplexer.Connect("localhost:6379"));
builder.Services.AddCacheWeaveDistributedCache(
    sp => sp.GetRequiredService<IConnectionMultiplexer>());

RemoveByPrefix: Supported only when an IConnectionMultiplexer is provided — uses Redis SCAN + DEL in batches of 250 across all endpoints. Throws InvalidOperationException if called without a multiplexer.

Use this provider when your project already registers IDistributedCache and you want CacheWeave to share the same backing store without adding a second Redis connection.


SQLite (CacheWeave.SQLite)

dotnet add package CacheWeave.SQLite
using CacheWeave.SQLite.Extensions;

builder.Services.AddCacheWeaveSQLite("Data Source=cache.db");

RemoveByPrefix: Supported via DELETE WHERE key LIKE 'prefix%'.

Suitable for edge deployments, embedded devices, or CI environments without Redis.


DynamoDB (CacheWeave.DynamoDB)

dotnet add package CacheWeave.DynamoDB
using CacheWeave.DynamoDB.Extensions;
using Amazon.DynamoDBv2;

builder.Services.AddAWSService<IAmazonDynamoDB>();
builder.Services.AddCacheWeaveDynamoDB(tableName: "CacheWeaveEntries");

The table must have a key (String) partition key and a ttl (Number) attribute with DynamoDB TTL enabled.

RemoveByPrefix: Not supported — throws NotSupportedException. Use exact key eviction only.


NCache (CacheWeave.NCache)

dotnet add package CacheWeave.NCache
using CacheWeave.NCache.Extensions;

builder.Services.AddCacheWeaveNCache(cacheName: "MyCache");

RemoveByPrefix: Not supported — throws NotSupportedException.


Memcached (CacheWeave.Memcached)

dotnet add package CacheWeave.Memcached
using CacheWeave.Memcached.Extensions;

builder.Services.AddCacheWeaveMemcached(opts =>
{
    opts.Servers.Add(new Server { Address = "localhost", Port = 11211 });
});

RemoveByPrefix: Not supported — Memcached has no key enumeration API.


FASTER KV (CacheWeave.Faster)

dotnet add package CacheWeave.Faster
using CacheWeave.Faster.Extensions;

builder.Services.AddCacheWeaveFaster(storagePath: "/tmp/faster-cache");

RemoveByPrefix: Not supported.

FASTER KV is optimised for extremely high throughput on local NVMe storage. Suitable for single-instance, latency-sensitive workloads.


Provider Comparison

Provider Distributed RemoveByPrefix Persistence Best For
Redis Yes Yes Optional (AOF/RDB) Production, multi-instance
InMemory No Yes No Dev, test, single-instance
DistributedCache Depends on backing store With multiplexer only Depends on backing store Reuse existing IDistributedCache
SQLite No Yes Yes Edge, embedded
DynamoDB Yes No Yes AWS-native, serverless
NCache Yes No Yes .NET enterprise
Memcached Yes No No Simple distributed cache
FASTER No No Yes Ultra-high throughput

Custom Provider

Implement ICacheProvider (or ICacheProviderInner) and register it:

public class MyCustomProvider : ICacheProviderInner
{
    public Task<string?> GetAsync(string key, CancellationToken ct = default) { ... }
    public Task SetAsync(string key, string value, TimeSpan? expiry = null, CancellationToken ct = default) { ... }
    public Task RemoveAsync(string key, CancellationToken ct = default) { ... }
    public Task RemoveByPrefixAsync(string prefix, CancellationToken ct = default) { ... }
}

// Register
builder.Services.AddCacheWeave();
builder.Services.AddSingleton<ICacheProviderInner, MyCustomProvider>();

Clone this wiki locally