Overview
TheCacheService provides a thread-safe abstraction over BoltDB cache operations. It manages post metadata, search indexes, HTML content, and hash tracking for incremental builds.
Source: builder/services/interfaces.go:26-58
Interface
Read Operations
GetPost
Retrieves post metadata by ID.Post ID (BLAKE3 hash of normalized path)
Post metadata including title, tags, HTML content, and hashes
Unique post identifier
Relative path from content directory
BLAKE3 hash of frontmatter
BLAKE3 hash of body content (v1.2.1)
HTML content for posts < 32KB
Content-addressed hash for large HTML (> 32KB)
GetPostsByIDs
Batch retrieves multiple posts in a single transaction.Array of post IDs to fetch
Map of post ID to metadata
GetSearchRecord
Retrieves pre-computed search data for a post.Post ID
GetHTMLContent
Retrieves rendered HTML content for a post.Post metadata containing either inline HTML or content hash
Rendered HTML content
Small posts (< 32KB) store HTML inline in metadata. Large posts use content-addressed storage.
Write Operations
StoreHTMLForPost
Stores rendered HTML for a post, automatically choosing inline or content-addressed storage.Post metadata to update
Rendered HTML content
BatchCommit
Commits multiple posts, search records, and dependencies in a single transaction.Array of post metadata to store
Map of post ID to search record
Map of post ID to dependencies (tags, templates)
DeletePost
Removes a post from cache (used when files are deleted).Post ID to delete
Hash Tracking
GetSocialCardHash / SetSocialCardHash
Tracks social card image generation state.Post path
Frontmatter hash (for Set operation)
GetWasmHash / SetWasmHash
Tracks WASM search engine compilation state.Directory hash of
cmd/search, builder/search, builder/modelsDirty Tracking
MarkDirty
Marks a post as needing re-render (used in watch mode).Post ID to mark dirty
IsDirty
Checks if a post needs re-rendering.Post ID to check
True if post needs re-rendering
Implementation
The default implementation iscacheServiceImpl with thread-safe dirty tracking:
builder/services/cache_service.go:10-24
Usage Example
Frombuilder/run/build.go:178-240:
builder/services/post_service.go:522-546:
Performance Features
In-Memory LRU Cache (v1.2.1)
Hot post metadata is cached in memory with 5-minute TTL:Body Hash Tracking (v1.2.1)
Separate body content hashing ensures body-only changes are detected:Batch Operations
Avoids N+1 queries by fetching multiple posts in single transaction:Related
- PostService - Post processing
- Cache Types - Cache data structures