On this page
Cache without weakening data guarantees
Use trusted scopes and define cross-replica invalidation.
Cache is a performance layer. The database remains authoritative for balances, quota consumption, permissions and licenses.
Define trusted scope
CacheScope combines tenant, company and app identifiers with escaping and explicit segment boundaries. Obtain those identifiers from authorized server context. Use an application-specific resource key and revision when the cached representation changes. Avoid user-controlled cross-scope lookups.
Select the adapter
Fabricators.Caching.FusionCache implements ICacheService without requiring EF. Fabricators.Infrastructure retains its existing facade for compatibility. New cache-only consumers should reference the separate adapter.
The default registration is process-local. Multiple replicas require a deliberate distributed store/backplane, serialization and invalidation strategy. Decide which read paths may tolerate stale values and which must consult the authority directly.
Do not cache ambient execution state
Keep per-request tenant context, EF contexts, credentials and rendering contexts out of shared cache entries. Compiled Scriban templates are not automatically safe to distribute across processes. Choose explicit DTOs and invalidate on meaningful domain changes after their transaction commits.
Verify isolation with identical resource names under different tenant/company/app scopes. Verify invalidation and failure behavior against the selected deployment.
Default metadata and template caches
AddFoundationHandlers and AddEndpoints cache immutable discovery results per
explicitly approved assembly. Weak assembly keys allow collectible assemblies to
be unloaded. They do not scan all loaded assemblies, cache service instances or
cache authorization decisions. Module order is snapshotted once per service
provider composed with AddModules; activation changes require a new host.
EF keeps its own model cache: when the module set varies within one process, the
host must include that set in its EF model cache key.
AddFabricatorsTemplates() enables a private process-local cache of parsed
Scriban syntax: 128 entries, 30-minute lifetime, with local stampede protection.
Keys hash the exact source content, so changed content is parsed immediately.
Parse errors are not cached. Each render creates a fresh context, data object and
output writer, preserving escaping, cancellation and existing resource limits.
Neither rendered output nor recipient data is cached. Identical template source
may share syntax across tenants because no tenant state is attached to the AST.
services.AddFabricatorsTemplates(options =>
{
options.MaximumEntries = 256;
options.Duration = TimeSpan.FromMinutes(15);
// Set Enabled = false to disable parsed-template reuse.
});The allowed bounds are 1–4096 entries and 1 second–1 day. This cache never uses the
host's shared IFusionCache, distributed cache or backplane; syntax trees remain
inside the renderer process. Disposal releases the private cache.
ScribanTemplateRenderer.CacheStatistics exposes parse/entry counts only, without
source text, cache keys or input data. These are diagnostic snapshots, not billing
or exact hit-rate metrics.
Do not add transparent caching to session validation, credential revocation, membership/license decisions, quota consumption, balances or write admission. Product query caches require explicit freshness and invalidation rules after commit. The general FusionCache adapter remains opt-in for those read models; it does not guarantee distributed single execution or transaction consistency.
Continue with the executable example or FusionCache adapter API.
Related integration guides
For variable EF models, see persistence composition. For already localized values, include the effective presentation in cache variation.