Documentation
¶
Overview ¶
Package templ provides a content-hash cache for .templ files so that `templ generate` is only invoked for files whose contents (or generated counterparts) have changed since the last run.
Cache layout: a flat {<relative-path>: sha256-hex} JSON map persisted at templCachePath. The format mirrors pkg/helpers/wasm/wasm_cache.go so both caches behave consistently and remain easy to inspect by hand.
Index ¶
Constants ¶
const TemplCachePath = ".gothicCli/templ-cache.json"
TemplCachePath is the on-disk location of the templ hash cache. Exported so callers (and tests) can override behavior if needed.
Variables ¶
This section is empty.
Functions ¶
func DirtyFiles ¶
DirtyFiles returns the subset of files whose hash differs from the cache or whose generated _templ.go counterpart is missing. Files that hash to "" (unreadable) are also returned so the caller surfaces the error via templ.
func HashFile ¶
HashFile computes the SHA-256 hex digest of a file's contents. Returns "" if the file cannot be read so callers can treat the file as dirty.
func ScanTemplFiles ¶
ScanTemplFiles walks root and returns the relative paths of every .templ file found. Hidden directories (".git", "node_modules", ".gothicCli") are skipped to avoid touching generated or vendored trees.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds per-file content hashes of .templ files. It is safe for concurrent use; callers typically Load, mutate via Update, then Save in a single hot-reload cycle.
func Load ¶
func Load() *Cache
Load reads the cache at TemplCachePath. Missing or malformed files yield an empty cache rather than an error — the cache is an optimization, never a correctness boundary.
func (*Cache) Invalidate ¶
Invalidate removes key from the cache (e.g., when the generated _templ.go counterpart is missing and we want to force regeneration).
func (*Cache) Save ¶
Save atomically writes the cache to disk (write to .tmp then rename). Failures are silent — the cache is best-effort.