JSPM

  • Created
  • Published
  • Downloads 695
  • Score
    100M100P100Q96375F
  • License MIT

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

Package Exports

  • fetch-json-cache
  • fetch-json-cache/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fetch-json-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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()