Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

json cache

Daniele Guido edited this page Oct 20, 2015 · 2 revisions

Histograph makes use of a file based cache, easily accessible, e.g for writing a cache content simply do:

var helpers = require ('helpers');
// ...
helpers.cache.write(contents, {
   namespace: 'services',
   ref: 'Rome, Italy'
}, function(err) {
   // handle err
})

First things first: make sure that the settings.paths.cache is correctly set; that the corresponding paths exists and are writable; and that the specific test for the cache mocha -g 'core:cache' does not throw any error (Cfr. mocha documentation for more info about testing with mocha).

The namespace options is compulsory and it define the subfolder where the cached file should be written.

reading

  ``` js
  helpers.cache.read({
    namespace: 'services',
    ref: 'Rome, Italy'
  }, function (err, contents) {
    // contents variable contains JSON parsed data or raw data if JSON parsing failed
    console.log(contents.results)
    done();
  })
  ``` js