Normalized
URL
key-value cache.
In an effort to prevent duplicates, unnecessary URL components will be (optionally) reduced/normalized.
Node.js >= 14
is required. To install, type this at the command line:
npm install urlcache
const URLCache = require('urlcache');
const cache = new URLCache(options);
Removes all stored key-value pairs that have expired.
Removes all stored key-value pairs.
Removes the url
key-value pair.
Returns the stored value for url
, or undefined
if there is none.
Returns true
if there is a stored value for url
.
Returns the number of stored key-value pairs.
Stores value
(any type) associated with url
key. Optionally, define options
to override any defined in the constructor.
const url = new URL('http://domain/');
cache.set(url, {'key':'value'});
cache.get(url); //-> {'key':'value'}
cache.set(url, new Promise(resolve => {
// set value after some delayed event
setTimeout(() => resolve('value'), 500);
});
console.log(await cache.get(url)); //-> 'value'
Type: Object
Default value: see minurl option profiles
A configuration of normalizations performed on URLs to hosts that may not be configured correctly or ideally.
Type: Object
Default value: see minurl option profiles
A configuration of normalizations performed on URLs to hosts that you expect to be configured correctly and ideally.
Type: Number
Default value: Infinity
The number of milliseconds in which a cached value should be considered valid.
Type: String
Default value: 'common'
The URL normalization profile. For example, value of 'common'
will use commonProfile
.
URLCache.DEFAULT_OPTIONS
is available for customizable extension.