Overview
Thekosh cache commands provide tools to inspect, maintain, and troubleshoot Kosh’s BLAKE3-based build cache. The cache stores rendered posts, search indexes, and SSR artifacts to enable fast incremental builds.
Usage
Subcommands
stats
Display cache statistics and performance metrics.- Schema Version: Cache format version (current: 2)
- Total Posts: Number of cached post metadata entries
- Total SSR: Count of server-side rendered artifacts (D2 diagrams, LaTeX math)
- Store Size: Total size of content-addressed blob storage
- Build Count: Number of builds performed
- Last GC: Timestamp of last garbage collection
- Inline Posts: Posts with HTML stored inline (< 32KB)
- Hashed Posts: Posts with HTML in content-addressed storage (≥ 32KB)
gc
Run garbage collection to remove orphaned cache entries.Show what would be deleted without actually deleting. Also accepts
-n.- After deleting many posts
- After changing post content significantly (orphans old HTML blobs)
- Store size grows much larger than content size
- Periodically (monthly) for maintenance
verify
Check cache integrity and detect corruption.- Orphaned blobs: Old content not yet GC’d (run
kosh cache gc) - Missing blobs: Corruption or manual deletion (run
kosh cache rebuild) - Hash mismatches: Cache corruption (run
kosh cache rebuild)
rebuild
Clear the cache to force a full rebuild on next build.- Cache verification shows errors
- Upgrading Kosh to a new version
- Debugging unexpected build behavior
- Template changes not triggering rebuilds
clear
Delete all cache data including the database file.rebuild. Use when:
- Cache database is corrupted
- Migrating to a new cache directory
- Troubleshooting cache-related crashes
inspect
Show detailed information about a specific cached file.- Full BLAKE3 hashes are truncated to first 8 and last 8 characters
- ContentHash: Hash of frontmatter + body content
- HTMLHash: Hash of rendered HTML output
- SSR Hashes: Hashes of D2 diagrams and LaTeX math inputs
Cache Architecture
Storage Strategy
Kosh uses a hybrid storage approach: Inline Storage (posts < 32KB):- HTML stored directly in metadata
- Faster access (single database read)
- Used for ~90% of typical posts
- HTML stored in blob storage by BLAKE3 hash
- Deduplicates identical content
- Reduces database size
Cache Keys
Post Metadata:- Primary key:
PostID(UUID v5 from path) - Indexed by:
Path,ContentHash
- Stored per-post with BM25 word frequencies
- Includes normalized title and content
- D2 diagrams and LaTeX math cached by input hash
- Prevents re-rendering unchanged diagrams
Invalidation
Cache entries are invalidated when:- Content changes: Frontmatter or body modified (detected via body hash)
- Template changes: Affecting templates trigger post re-render
- Dependency changes: Global CSS, config, etc.
- Manual clear:
kosh cache rebuildorkosh cache clear
Performance Impact
Typical build performance with cache:| Scenario | Build Time | Cache Hit Rate |
|---|---|---|
| Full rebuild (cold cache) | 10.2s | 0% |
| No changes | 0.8s | 100% |
| Single post edit | 1.2s | 98% |
| Template change | 3.4s | 0% (rehydrate) |
| Config change | 9.8s | 0% |
Cache Location
Default cache directory:.kosh-cache/ in project root.
Override in kosh.yaml:
Cache Modes
Production Mode (default):- Full durability with fsync
- Safer but slightly slower
- Used by
kosh buildand cache commands
- Less durable, faster writes
- Used by
kosh serve --dev - Acceptable risk for local development
Troubleshooting
Cache Not Working
- Check stats:
kosh cache stats- verify cache has entries - Verify integrity:
kosh cache verify - Rebuild cache:
kosh cache rebuild
Cache Too Large
- Run GC:
kosh cache gc- remove orphaned blobs - Check SSR artifacts: Many diagrams? Consider optimization
- Inspect large posts:
kosh cache inspect <path>
Stale Content
If builds show old content:- Force rebuild:
kosh clean --cache && kosh build - Check mod times: File system times correct?
- Verify hashes:
kosh cache inspect <path>- ContentHash should change
Related Commands
kosh build- Uses cache for fast buildskosh clean- Clean output and optionally cache