Documentation
¶
Overview ¶
Package cache provides caching utilities for the build pipeline.
ContentCache (the main type in this package) caches loaded page content keyed by content-relative path, with LRU eviction and mtime-based invalidation. It is safe for concurrent use.
Index ¶
- type ContentCache
- func (c *ContentCache) Clear()
- func (c *ContentCache) GetOrLoad(path string, loadFn LoadPageFunc) (*content.Page, error)
- func (c *ContentCache) Invalidate(path string)
- func (c *ContentCache) InvalidateByPrefix(prefix string)
- func (c *ContentCache) Len() int
- func (c *ContentCache) Store(path string, pg *content.Page, mtime time.Time)
- type ContextCache
- type LoadPageFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentCache ¶
type ContentCache struct {
// contains filtered or unexported fields
}
ContentCache provides LRU caching for loaded content pages. Key is the content-relative path (e.g. "posts/hello.md"). Cache entries are invalidated when the file's mtime changes.
func NewContentCache ¶
func NewContentCache(max int) *ContentCache
NewContentCache creates a ContentCache with the given max entries. max must be > 0; values <= 0 are treated as 5000.
func (*ContentCache) Clear ¶
func (c *ContentCache) Clear()
Clear removes all entries from the cache.
func (*ContentCache) GetOrLoad ¶
func (c *ContentCache) GetOrLoad(path string, loadFn LoadPageFunc) (*content.Page, error)
GetOrLoad returns the cached page for path if it exists. If the cache misses, it calls loadFn to load the page, caches it (evicting the LRU entry if at capacity), and returns the result. loadFn is only called when needed.
NOTE: This cache uses caller-driven invalidation — callers must call Invalidate/InvalidateByPrefix/Clear when files change (typically via the file watcher in daemon mode). The cache does NOT re-stat the filesystem on GetOrLoad, so stale entries are returned until explicitly invalidated.
Concurrent calls to GetOrLoad with the same path are safe: only one goroutine calls loadFn; the others wait and receive the cached result.
func (*ContentCache) Invalidate ¶
func (c *ContentCache) Invalidate(path string)
Invalidate removes a single entry from the cache by path.
func (*ContentCache) InvalidateByPrefix ¶
func (c *ContentCache) InvalidateByPrefix(prefix string)
InvalidateByPrefix removes all entries whose key starts with the given prefix. Useful for directory-level invalidation when files are added or removed.
func (*ContentCache) Len ¶
func (c *ContentCache) Len() int
Len returns the current number of cached entries.
func (*ContentCache) Store ¶
Store inserts or updates a cache entry for path with the given page and mtime. This is a single-lock write operation without the double-checked loading overhead of GetOrLoad. Use it when you already have fresh data and just want to populate the cache (e.g., write-through pattern from full builds).
Unlike GetOrLoad, Store does not call loadFn and does not check for existing entries — it unconditionally writes the entry.
type ContextCache ¶
type ContextCache struct {
// contains filtered or unexported fields
}
ContextCache caches template contexts per page. Cache entries are invalidated when the page's version changes. It uses a simple map (no LRU) since it is scoped to a single build and does not survive across builds like ContentCache.
func NewContextCache ¶
func NewContextCache() *ContextCache
NewContextCache creates a new ContextCache.
func (*ContextCache) Clear ¶
func (c *ContextCache) Clear()
Clear removes all entries from the cache.
func (*ContextCache) Get ¶
func (c *ContextCache) Get(pg *content.Page) *tmpl.Context
Get returns the cached template context for pg if the page's version matches the cached version. Returns nil on miss or version mismatch.
func (*ContextCache) Invalidate ¶
func (c *ContextCache) Invalidate(pg *content.Page)
Invalidate removes the cache entry for pg, if any.
func (*ContextCache) Len ¶
func (c *ContextCache) Len() int
Len returns the number of cached entries.