Cache¶
The Cache module generates typed per-entity cache interfaces, ICacheStore-backed implementations, effect methods, capability interfaces, and DI registration from [CacheStore] and [Cached] attributes. This follows the same pattern as Data Store.
Under the hood, all generated cache implementations delegate to ICacheStore — a low-level string-key cache interface backed by IDistributedCache. Any .NET distributed cache provider (Redis, SQL Server, NCache) works out of the box by registering an IDistributedCache implementation.
Quick Start¶
Define a cache store and cached entities:
using Deepstaging;
using Deepstaging.Caching;
[CacheStore]
public static partial class AppCache;
[TypedId] public readonly partial struct ProductId;
[Cached(ExpirationSeconds = 600)]
public record Product(ProductId Id, string Name, decimal Price);
This generates:
IProductCache— typed async cache interface with get/set/removeProductCache— delegates toICacheStorewith key prefix"product:{id}"TestProductCache— test double with call recording and seedable stateIHasAppCache— capability interface for runtime accessAppCache.Products.*—Eff<RT, T>effect methodsAddAppCache— DI registration (registersICacheStore+ typed caches)
Compose with effect pipelines:
var program =
from cached in AppCache.Products.Get<AppRuntime>(productId)
from result in cached.Match(
Some: p => SuccessEff(p),
None: () =>
from product in AppStore.Products.GetById<AppRuntime>(productId)
from _ in product.Match(
Some: p => AppCache.Products.Set<AppRuntime>(productId, p),
None: () => unitEff)
select product)
select result;
What's Next¶
| Page | Description |
|---|---|
| Attribute Reference | [CacheStore], [Cached] — targets, properties, defaults, and constraints |
| Generated Code | Cache interfaces, ICacheStore-backed implementations, DI registration — plain .NET with async/await |
| Effects Composition | Capability interfaces, Eff<RT, T> methods, OpenTelemetry tracing, runtime composition |
ICacheStore¶
Generated caches delegate to ICacheStore — a low-level string-key interface backed by IDistributedCache. Any .NET distributed cache provider (Redis, SQL Server, NCache) works out of the box. See Generated Code for the full interface and production setup.