fossasia/loklak_webclient

View on GitHub
iframely/lib/plugins/system/meta/cachedMeta.js

Summary

Maintainability
A
0 mins
Test Coverage
var async = require('async');
var cache = require('../../../cache');
var sysUtils = require('../../../../logging');

module.exports = {

    provides: ['__noCachedMeta', 'meta'],

    getData: function(url, options, cb) {

        if (options.refresh) {

            cb(null, {
                __noCachedMeta: true
            });

        } else {

            var meta_key = 'meta:' + url;

            cache.get(meta_key, function(error, data) {

                if (error) {
                    sysUtils.log('   -- Error loading cached meta for: ' + url + '. ' + error);
                }

                if (!error && data) {

                    sysUtils.log('   -- Using cached meta for: ' + url);

                    cb(error, {
                        meta: data
                    });

                } else {

                    cb(null, {
                        __noCachedMeta: true
                    });
                }
            });
        }
    }

};