Gist 6547269
✓ Published0🌍 Public
Aalessioalex
Last edited Jul 23, 2013
Created on Sep 13, 2013
This example shows a caching layer for the npm registry, which retrieves package metadata documents and keeps them in a local LRU cache. It demonstrates how to use the `lru-cache` module for in-memory storage, `couchwatch` to subscribe to real-time changes from the CouchDB-based registry database at `http://isaacs.iriscouch.com/registry`, and `request` to fetch individual package documents on cache misses. When a change row arrives, the corresponding cache entry is deleted, ensuring the cache stays fresh. The code defines a `RegistryCache` constructor with a `get` method that returns cached data or fetches it via HTTP, handling errors and non-200 responses.
AI-generated description