0.0.3 β’ Published 8 months ago
@_all_docs/cache v0.0.3
@_all_docs/cache
Stability: NaN β
Array(16).join("wat" - 1) + " Batman!"
Fetch & cache :origin/_all_docs using a set of lexographically sorted keys
Features Β· How It Works Β· Thanks
Features
- ποΈ Relax! Use the
start_keyandend_keyCouchDB APIs to harness the power of partition-tolerance from the b-tree - π Accepts a set of lexographically sorted pivots to use as B-tree partitions
- π¦Ώ Run map-reduce operations on
_all_docsandpackumententries by key range or cache partition - π ~πΈοΈβ‘οΈπ’π¦π¦ Lightning fast partition-tolerant edge read-replica for
cache-control: immutable"Pouch-like"[{ _id, _rev, ...doc }*]JSON documents out of the box!~
Usage
pnpm install @_all_docs/cacheπ² π Here. Be. Dragons π€― Letting the interface(s) reveal themselves for now. No official interface π€
_all_docs_*bin scripts fornpxincluded below
1οΈβ£ Fetch _all_docs by partitions created from pivots
DEBUG=_all_docs* PIVOTS=a.string.array.js npx _all_docs_from_origin
# Inspect partitions fetched to _all_docs cache
ls -al cache/*__*.jsona.string.array.js (naive)
module.exports = [
null,
...numbers,
...atoz
];2οΈβ£ Fetch packuments for a cached _all_docs partition
DEBUG=_all_docs* npx _all_docs_partipacku A___ZHow it works
1οΈβ£ Fetch _all_docs for pivots
- π Provide
npmorigin, lexographic pivots, & location for existing cache (if any) - β‘οΈ Create
[{ start_key, end_key, id, filename }]partition ranges from lexographic pivots - πββοΈ For each
[start_key, end_key]partition:- ποΈ Attempt to read
${start_key}___${end_key}.jsonfrom local disk cache- β
Set
max-age=${now-last.now}s to HTTPheadersfor the outboundundicioptions.
- β
Set
- β¬οΈ
GET :npm-origin/_all_docs?start_key={start_key}&end_key={end_key}&include_docs=false
- ποΈ Attempt to read
- π Validate the HTTP response:
- β
304 Not ModifiedLocal Cache Valid. No update necessary - π
200 OKUpdate cache contents for${start_key}___${end_key}.jsonpartition
- β
2οΈβ£ Fetch packuments for _all_docs partition
π
Thanks
Many thanks to bmeck, guybedford, mylesborins, mikeal, jhs, jchris, darcyclarke, isaacs, & mcollina for all the code, docs, & past conversations that contributed to this technique working so well, 10 years later β€οΈ