URL key-value cache for Node.js (>=0.10) that stores values keyed by URL strings or parsed URL objects. Version 0.7.0 is the latest release, supporting Node.js v9. It normalizes URLs by default to avoid duplicate keys, offers optional expiry times for cached values, and can strip URL hashes. Compared to simple Map-based caching, urlcache provides URL normalization and expiry out of the box. The API is minimal: get, set, clear, and length methods. Note that versions <0.7 require an Object.assign polyfill for Node <4, and the API has changed across releases (Promises removed in 0.5, .length added in 0.6).
npm install urlcacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of urlcache: setting, getting, clearing a cached value with expiry, and handling promises as values.
Use Promise.resolve(cache.get(url)) if you expect promise-wrapped values, or remove .then() calls on .set().
Node.js >=4.0 is recommended; for older versions, provide a global Object.assign polyfill (e.g., require('object.assign').shim()).Refer to the changelog and update your usage of .set() and .get() to match the new API.
Set options.stripUrlHashes: false if you need to differentiate cache entries by URL fragments.
Set options.normalizeUrls: false if you want to use raw URLs as keys.
Use 'new UrlCache(options)' instead of 'UrlCache(options)'.
Use dynamic import: const UrlCache = (await import('urlcache')).default; Or switch to CommonJS.Upgrade to version 0.6.0+ and use .length() method.
If you set a Promise as a value, use Promise.resolve(cache.get(url)).then(...) to handle the resolved value.
Run 'npm install urlobj' alongside urlcache.