feat(corpus): cache the metadata tables by sha256 between sessions (#64)
R/cache.R was a stub, so a remote session read the ten metadata tables (about 3 MB) over HTTP every time. cog_open() now keeps them in USCOGDATA_CACHE_DIR/corpus/ and points the metadata views there. A cached file is used only while its sha256 matches the session's manifest; a download is checked before it replaces anything. Any failure (an HTTP error such as Hugging Face's 429, a mismatch, an unwritable directory) falls back to remote reads with a message. A local corpus is read in place and never cached. The yearly partitions stay remote; cog_mirror() is still the tool for repeat work on them. Against the public corpus, 2026-11-12, one run each, fresh cache: session open 1.76 s cold -> 0.38 s warm first query 1.16 s cold -> 0.68 s warm cog_spending() for Madison (552025209777), 2012 and 2020, returns the same 46 rows and the same digest as main. Live-corpus tests pass. Closes #64 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+238
-11
No files matched your search
+2
-1
@@ -32,7 +32,8 @@ cog_open <- function(url = .resolve_url(),
|
||||
.validate_schema(manifest, supported = c(4L, 5L, 6L, 7L))
|
||||
.validate_scope(manifest)
|
||||
|
||||
.register_views(con, url, manifest)
|
||||
meta_url <- .cache_metadata_tables(url, manifest, cache_dir)
|
||||
.register_views(con, url, manifest, meta_url = meta_url)
|
||||
|
||||
.uscogdata_env$con <- con
|
||||
.uscogdata_env$manifest <- manifest
|
||||
|
||||
Reference in new issue
Block a user