Skip to content

Latest commit

 

History

History
83 lines (66 loc) · 2.72 KB

cache.md

File metadata and controls

83 lines (66 loc) · 2.72 KB

Table of Contents

amna.cache

The cache engine is currently setup to use mongodb as the cache store, this will likely become more flexible in the future.

API

Read from cache

amna.cache( ... any number of key arguments ... ).read([maxage,] function (err, record) {
    console.log('Got cache record:', record.key, record.value);
});

Example:

amna.cache('california', 'population').read('1w', function (err, record) {
    if (err) throw err;

    if (record) {
        console.log('Got the population of CA from cache:', record.value);
    }

    else {
        console.log('Cache either not set, or is older than 1 week, cannot be trusted.');
    }
});

Save to cache

amna.cache( ... any number of key arguments ... ).save(value, function (err, record) {
    console.log('Saved cache record:', record.key, record.value);
});

Example:

amna.cache('california', 'population').set(38.33e6, function (err, record) {
    if (err) throw err;

    console.log('Saved CA population to cache:', record.value);
});