πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

@_all_docs/cache

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@_all_docs/cache

Fetch, cache, & map/reduce :origin/{_all_docs,:packument}` documents for a set of lexographically sorted pivots by range or partition

0.0.3
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
Β 
Created
Source

@_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_key and end_key CouchDB 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_docs and packument entries 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 for npx included 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/*__*.json

a.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___Z

How it works

1️⃣ Fetch _all_docs for pivots

  • πŸ“ Provide npm origin, 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}.json from local disk cache
      • βœ… Set max-age=${now-last.now}s to HTTP headers for the outbound undici options.
    • ⬇️ GET :npm-origin/_all_docs?start_key={start_key}&end_key={end_key}&include_docs=false
  • πŸ‘€ Validate the HTTP response:
    • βœ… 304 Not Modified Local Cache Valid. No update necessary
    • πŸ“ 200 OK Update cache contents for ${start_key}___${end_key}.json partition

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 ❀️

Keywords

relax

FAQs

Package last updated on 03 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts