-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
816fb30
commit 1e5b6c3
Showing
8 changed files
with
545 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
coverage/ | ||
index-es5.js | ||
index-es5.js.map | ||
node_modules/ | ||
.nyc_output/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
- 4 | ||
- 6 | ||
- 8 | ||
- node | ||
script: npm test | ||
- 14 | ||
- node | ||
script: npm run ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,95 @@ | ||
# urlcache [![NPM Version][npm-image]][npm-url] [![Bower Version][bower-image]][bower-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][david-image]][david-url] | ||
# urlcache [![NPM Version][npm-image]][npm-url] ![File Size][filesize-image] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Monitor][greenkeeper-image]][greenkeeper-url] | ||
|
||
> URL key-value cache. | ||
> Normalized [`URL`](https://mdn.io/URL/) key-value cache. | ||
## Installation | ||
|
||
[Node.js](http://nodejs.org/) `>= 0.10` is required; `< 4.0` will need an `Object.assign` polyfill. To install, type this at the command line: | ||
In an effort to prevent duplicates, unnecessary URL components will be (optionally) reduced/normalized. | ||
|
||
|
||
## Installation | ||
|
||
[Node.js](https://nodejs.org) `>= 14` is required. To install, type this at the command line: | ||
```shell | ||
npm install urlcache | ||
``` | ||
|
||
|
||
## Constructor | ||
```js | ||
var UrlCache = require("urlcache"); | ||
var cache = new UrlCache(options); | ||
const URLCache = require('urlcache'); | ||
const cache = new URLCache(options); | ||
``` | ||
|
||
|
||
## Methods | ||
**Note:** all instances of `url` can be either a `String` or a [`url.parse()`](https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost)-compatible `Object`. | ||
## 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. | ||
|
||
### .clear([url]) | ||
Removes the `url` key-value pair. If the `url` argument is not defined, *all* pairs will be removed. | ||
### `.get(url)` | ||
Returns the stored value for `url`, or `undefined` if there is none. | ||
|
||
### .get(url) | ||
Returns the stored value of `url`. If no such value exists, `undefined` will be returned. | ||
### `.has(url)` | ||
Returns `true` if there is a stored value for `url`. | ||
|
||
### .length() | ||
### `.length` | ||
Returns the number of stored key-value pairs. | ||
|
||
### .set(url, value[, expiryTime]) | ||
Stores `value` (any type) into `url` key. Optionally, define `expiryTime` to override `options.expiryTime`. | ||
### `.set(url, value[, options])` | ||
Stores `value` (any type) associated with `url` key. Optionally, define `options` to override any defined in the constructor. | ||
```js | ||
cache.set("url", {"key":"value"}); | ||
cache.get("url"); //=> {"key":"value"} | ||
|
||
cache.set("url", new Promise(function(resolve, reject) { | ||
// set value after some delayed event | ||
setTimeout(function() { | ||
resolve("value"); | ||
}, 500); | ||
}); | ||
const url = new URL('http://domain/'); | ||
|
||
cache.set(url, {'key':'value'}); | ||
cache.get(url); //-> {'key':'value'} | ||
|
||
Promise.resolve(cache.get("url")).then(function(value) { | ||
console.log(value); //=> "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 | ||
### options.defaultPorts | ||
### `carefulProfile` | ||
Type: `Object` | ||
Default value: see [urlobj.parse() options](https://github.com/stevenvachon/urlobj) | ||
A map of protocol default ports for `options.normalizeUrls`. | ||
Default value: see [minurl option profiles](https://npmjs.com/minurl#option-profiles) | ||
A configuration of normalizations performed on URLs to hosts that may not be configured correctly or ideally. | ||
### options.expiryTime | ||
### `commonProfile` | ||
Type: `Object` | ||
Default value: see [minurl option profiles](https://npmjs.com/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. | ||
### options.normalizeUrls | ||
Type: `Boolean` | ||
Default value: `true` | ||
When `true`, will remove unnecessary URL parts in order to avoid duplicates in cache. | ||
### options.stripUrlHashes | ||
Type: `Boolean` | ||
Default Value: `true` | ||
When `true`, will remove `#hashes` from URLs. They are most likely not useful to you because they are local to the document that contains them. | ||
### `profile` | ||
Type: `String` | ||
Default value: `'common'` | ||
The URL normalization profile. For example, value of `'common'` will use `commonProfile`. | ||
## Changelog | ||
* 0.7.0 support for Node.js v9 | ||
* 0.6.0 added `.length()` and removed `Object.assign()` polyfill | ||
* 0.5.0 removed use of Promises as they were unnecessary | ||
* 0.4.0 simpler `Promise`-based API | ||
* 0.3.0 added `options.defaultPorts`, more tests | ||
* 0.2.0 simplified API | ||
* 0.1.0 initial release | ||
### Default Options | ||
`URLCache.DEFAULT_OPTIONS` is available for customizable extension. | ||
[npm-image]: https://img.shields.io/npm/v/urlcache.svg | ||
[npm-url]: https://npmjs.org/package/urlcache | ||
[bower-image]: https://img.shields.io/bower/v/urlcache.svg | ||
[bower-url]: https://github.com/stevenvachon/urlcache | ||
[filesize-image]: https://img.shields.io/badge/bundle-40kB%20gzipped-blue.svg | ||
[travis-image]: https://img.shields.io/travis/stevenvachon/urlcache.svg | ||
[travis-url]: https://travis-ci.org/stevenvachon/urlcache | ||
[david-image]: https://img.shields.io/david/stevenvachon/urlcache.svg | ||
[david-url]: https://david-dm.org/stevenvachon/urlcache | ||
[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/urlcache.svg | ||
[coveralls-url]: https://coveralls.io/github/stevenvachon/urlcache | ||
[greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/urlcache.svg | ||
[greenkeeper-url]: https://greenkeeper.io/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.