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);
.clean()
Removes all stored key-value pairs that have expired.
.clear()
Removes all stored key-value pairs.
.delete(url)
Removes the url
key-value pair.
.get(url)
Returns the stored value for url
, or undefined
if there is none.
.has(url)
Returns true
if there is a stored value for url
.
.length
Returns the number of stored key-value pairs.
.set(url, value[, options])
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'
carefulProfile
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.
commonProfile
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.
maxAge
Type: Number
Default value: Infinity
The number of milliseconds in which a cached value should be considered valid.
profile
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.