Expand description
Machine-local SQLite cache for fast entry lookups.
The cache lives at $XDG_CACHE_HOME/archelon/{journal_id}/cache.db — outside
the journal directory so it is never synced by git, Syncthing, or Nextcloud.
§Sync strategy
On each invocation, all .md files are stat()-ed (O(n), syscalls only).
Per-file mtime comparison is used rather than a global last_synced_at
timestamp: syncing tools such as Syncthing preserve the original mtime, so a
global watermark would miss files changed or deleted on another machine.
The sync:
- New / modified files (mtime changed or path not in DB): re-parsed and upserted.
- Deleted files (path in DB but gone from disk): removed from cache. Handles Syncthing/Nextcloud propagated deletions transparently.
Explicit deletion after archelon entry remove is handled by
remove_from_cache, which avoids a full sync round-trip in that hot path.
§Schema
files: tracks every.mdfile ever scanned (path + mtime). Covers both managed entries and non-managed files (e.g.README.md). A file whose mtime is unchanged is skipped entirely on subsequent syncs — preventing repeated parse-failure warnings for unmanaged files.entries: managed-entry metadata.id INTEGER PRIMARY KEYuses CarettaId as i64.pathhas an FK tofiles(path) ON DELETE CASCADEso removing a row fromfilesautomatically removes the corresponding entry.tags: many-to-many tag index for efficient tag filtering.entries_fts: FTS5 virtual table (trigram tokenizer) overtitle+bodyfor full-text search. Trigram enables substring search and CJK text with no spaces.
§Schema versioning
SCHEMA_VERSION is stored in SQLite’s PRAGMA user_version.
- DB version = 0 (fresh file): schema is applied and version is set.
- DB version < app version: schema changed; cache is wiped and rebuilt automatically.
- DB version > app version: the cache was created by a newer archelon; an error is
returned instructing the user to update archelon or run
archelon cache rebuild.
Structs§
- Cache
Info - Summary information about the current cache state.
- Search
Result - A result returned by
search_fts_entries.
Constants§
- SCHEMA_
VERSION - Stored in
PRAGMA user_version. Increment whenever the schema changes.
Functions§
- cache_
info - Collect cache statistics for display.
- db_path
- Compute the path to the current-version SQLite cache file within
cache_dir. - find_
entry_ by_ id - Look up an entry by its
CarettaId. - find_
entry_ by_ title - Look up an entry by its exact title.
- list_
entries_ from_ cache - Read all entries from the cache as [
EntryHeader] structs (no body). - open_
cache - Open (or create) the SQLite cache for
journal. - open_
cache_ vec - Open (or create) the cache with the sqlite-vec extension loaded.
- rebuild_
cache - Delete the current-version cache file and create a fresh one.
- remove_
from_ cache - Remove an entry row from the cache by file path.
- search_
fts_ entries - Full-text search using the FTS5 trigram index.
- sync_
cache - Incrementally sync the cache against the journal’s
.mdfiles. - upsert_
entry_ from_ path - Upsert a single entry into the cache by re-reading its file.