Implementation:1broseidon Ketch cache NewTagIndex
| Knowledge Sources | |
|---|---|
| Domains | Caching, Tagging |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Creates the independent, durable bookmark index that outlives page-cache expiry, opening its bbolt file only per operation so the CLI, crawls, and MCP servers share it without locking.
Description
NewTagIndex returns a `*Cache` backed by a `tagDB` that owns a path (never a process-lifetime handle) — ADR-0006. The index lives in a separate `tags.db` (config dir or `KETCH_TAGS_PATH`); the page cache lives in its own file. Membership is keyed by source URL, never by cookie/UA/rewrite keys. The optional `pages` cache is used for warmth checks (`cached: true/false`) only; a nil or unavailable page cache returns `cached: false` with `cache_status: unavailable`.
Usage
Called once by the CLI tag commands, the MCP `NewServer`, and the `--tag` writer. `Close` is unnecessary (no handle is held). Validate names/URLs with `ValidateTagName`/`ValidateBookmarkURL` before any Put.
Code Reference
Source Location
- Repository: ketch
- File: cache/tags.go, cache/tag_store.go, cache/boltfile.go
Signature
// NewTagIndex creates an independent, lazy index. pages may be nil or unavailable;
// no database handle is opened or retained here. Close is unnecessary.
func NewTagIndex(ttl time.Duration, pages *Cache) *Cache
// ValidateTagName applies the same rules at package, CLI, and MCP boundaries.
func ValidateTagName(name string) error
// ValidateBookmarkURL: an absolute http(s) URL with a host.
func ValidateBookmarkURL(raw string) error
Import
import (
"time"
"github.com/1broseidon/ketch/cache"
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ttl | time.Duration | Yes | Tag index TTL (for warmth checks) |
| pages | *cache.Cache | No | Shared page cache for warmth checks (nil-safe) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | *cache.Cache | Tag-index-backed cache; opens bbolt per operation |
Usage Examples
CLI / MCP Index
ttl, _ := time.ParseDuration(cfg.CacheTTL)
tags := cache.NewTagIndex(ttl, pageCache)
// tags.TagPage / tags.ShowTag / tags.RemoveTag … no Close needed.
Validation
if err := cache.ValidateTagName(name); err != nil {
return err // map to [validation] / exit 2
}
if err := cache.ValidateBookmarkURL(url); err != nil {
return err
}