Skip to content

stevenvachon/urlcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

urlcache NPM Version File Size Build Status Coverage Status Dependency Monitor

Normalized URL key-value cache.

In an effort to prevent duplicates, unnecessary URL components will be (optionally) reduced/normalized.

Installation

Node.js >= 14 is required. To install, type this at the command line:

npm install urlcache

Constructor

const URLCache = require('urlcache');
const cache = new URLCache(options);

Methods & Properties

.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'

Options

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.

Default Options

URLCache.DEFAULT_OPTIONS is available for customizable extension.