0.2.9 • Published 2 years ago

fetch-json-cache v0.2.9

Weekly downloads
10
License
MIT
Repository
github
Last release
2 years ago

fetch-json-cache

Caches fetched json. Updates when etag changes and is uses cache regardless if endpoint unreachable. Uses write-file-atomic for safe updates.

var Cache = require('fetch-json-cache');
var assert = require('assert');

var cache = new Cache('/path/to/cache');

//////////////
// callbacks
//////////////

// get
cache.get('https://jsonplaceholder.typicode.com/users', function(err, json) {
  assert.ok(!err);
  assert.ok(json.length > 0);
})

// get with forced update
cache.get('https://jsonplaceholder.typicode.com/users', { force: true }, function(err, json) {
  assert.ok(!err);
  assert.ok(json.length > 0);
})

// clear the cache
cache.clear(function(err) {
  assert.ok(!err);
})

//////////////
// promise
//////////////

// get
var json = await cache.get('https://jsonplaceholder.typicode.com/users')
assert.ok(json.length > 0);

// get with forced update
var json2 = await cache.get('https://jsonplaceholder.typicode.com/users', { force: true })
assert.ok(json2.length > 0);

// clear the cache
await cache.clear()
0.1.11

2 years ago

0.1.12

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago