diff --git a/README.md b/README.md index f8047e0..abf59fe 100644 --- a/README.md +++ b/README.md @@ -156,12 +156,10 @@ The set function must accept a key (which will be a string) and a value (which w The get function should accept a key and return whatever value was set for that key (or `undefined`/`null` if there is no value for that key). -The remove function should accept a key and remove the cached value associated with that key, if any. +The remove function should accept a key and remove the cached value associated with that key, if any. It is also safe for your caching delegate to remove values from the cache arbitrarily if desired (for example if you want to implement a TTL in the caching delegate). Both functions can be async. -It is safe to remove values from the cache arbitrarily (for example if you implement a TTL in the caching delegate). - For example, you could make and use your own simple memory cache like this: ```js @@ -180,7 +178,31 @@ class MyMemoryCache { } const fetchBuilder = require('node-fetch-cache'); -fetch = fetchBuilder.withCache(new MyMemoryCache()); +const fetch = fetchBuilder.withCache(new MyMemoryCache()); + +fetch('http://google.com') + .then(response => response.text()) + .then(text => console.log(text)); +``` + +## Importing as an ES Module + +You can import this library as an ES module: + +```js +import fetch from 'node-fetch-cache'; + +fetch('http://google.com') + .then(response => response.text()) + .then(text => console.log(text)); +``` + +The default import also doubles as a `fetchBuilder`, so you can use it like so if you want to customize the caching: + +```js +import fetchBuilder from 'node-fetch-cache'; + +const fetch = fetchBuilder.withCache(new fetchBuilder.MemoryCache({ ttl: 10000 })); fetch('http://google.com') .then(response => response.text()) diff --git a/package.json b/package.json index 5b2877c..9d00a74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-fetch-cache", - "version": "2.0.1", + "version": "2.0.2", "description": "node-fetch with a persistent cache.", "main": "index.js", "scripts": {