---
title: In-memory template cache
weight: 11
---
Each `Sword` instance has a 128-entry least-recently-used cache shared by its clones. Configure the entry bound or disable the cache with zero:
```rust
use rustysan_sword::{Config, Sword};
let sword = Sword::new(Config::default()).with_cache_capacity(64);
let stats = sword.cache_stats();
assert_eq!(stats.capacity, 64);
```
The Laravel adapter shares a process-local 128-entry cache across every application in the process (entries are keyed by name, resolved path, and full source, so applications never see each other's templates, but they do share the capacity), exposed for inspection by `rustysan_sword::laravel::cache_stats()`. The limit counts templates, not bytes; application template sizes remain relevant to memory use. Entries are keyed by logical name and resolved path, with the entire source compared for freshness. `render_source` uses its supplied name and source. Root resolution and all visited files are read on every render, in development and production, so an edit or lookup-precedence change is observed on the next render even when timestamps or lengths do not change. Untaken dependencies are not opened. Failed parses and compilations are not cached.
A warm root avoids Sword parsing and MiniJinja compilation; a warm include, layout, or component avoids Sword parsing and translation. MiniJinja still compiles dependencies for each render because its public environment loader caches them inside a render-specific environment. This keeps lazy lookup and the request-local callbacks independent. Request data, rendered slots, section contents, stacks, and once markers are never stored in the cache. No artifacts persist to disk, and the cache does not prevent in-flight renders from temporarily retaining evicted artifacts.
A reproducible local benchmark uses `cargo run --release --example cache_bench -- /path/to/showcase/resources/views`. It renders the showcase page with the data in that example, averages 30 newly constructed renderers for cold results, then 200 renders on one warmed renderer. On the development Mac, before caching the means were 0.889 ms cold and 0.590 ms repeated; after caching they were 0.678 ms and 0.226 ms. These are single local runs with filesystem and OS caches in effect, not a production throughput guarantee.