How to use @hapi/catbox - 5 common examples

To help you get started, we’ve selected a few @hapi/catbox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hapijs / hapi / lib / route.js View on Github external
this._assert(!this.settings.validate.payload || this.settings.payload.parse, 'Route payload must be set to \'parse\' when payload validation enabled');
        this._assert(!this.settings.validate.state || this.settings.state.parse, 'Route state must be set to \'parse\' when state validation enabled');
        this._assert(!this.settings.jsonp || typeof this.settings.jsonp === 'string', 'Bad route JSONP parameter name');

        // Authentication configuration

        this.settings.auth = (this._special ? false : this._core.auth._setupRoute(this.settings.auth, path));

        // Cache

        if (this.method === 'get' &&
            typeof this.settings.cache === 'object' &&
            (this.settings.cache.expiresIn || this.settings.cache.expiresAt)) {

            this.settings.cache._statuses = new Set(this.settings.cache.statuses);
            this._cache = new Catbox.Policy({ expiresIn: this.settings.cache.expiresIn, expiresAt: this.settings.cache.expiresAt });
        }

        // CORS

        this.settings.cors = Cors.route(this.settings.cors);

        // Security

        this.settings.security = Security.route(this.settings.security);

        // Handler

        this.settings.handler = Handler.configure(handler, this);
        this._prerequisites = Handler.prerequisitesConfig(this.settings.pre);

        // Route lifecycle
github TheScienceMuseum / collectionsonline / bin / cache.js View on Github external
const Catbox = require('@hapi/catbox');
const CatboxRedis = require('@hapi/catbox-redis');
var elasticacheHost = '127.0.0.1';
var elasticachePort = '6379';

if (process.env.ELASTICACHE_EP) {
  var config = process.env.ELASTICACHE_EP.split(':');
  elasticacheHost = config[0];
  elasticachePort = config[1];
}

module.exports = new Catbox.Client(CatboxRedis, {host: elasticacheHost, port: elasticachePort});
github hapijs / hapi / lib / core.js View on Github external
const name = config.name || '_default';
            Hoek.assert(!this.caches.has(name), 'Cannot configure the same cache more than once: ', name === '_default' ? 'default cache' : name);

            let client = null;

            if (config.provider) {
                let provider = config.provider;
                if (typeof provider === 'function') {
                    provider = { constructor: provider };
                }

                client = new Catbox.Client(provider.constructor, provider.options || { partition: 'hapi-cache' });
            }
            else {
                client = new Catbox.Client(config.engine);
            }

            this.caches.set(name, { client, segments: {}, shared: config.shared || false });
            added.push(client);
        }

        return added;
    }
github hapijs / hapi / lib / core.js View on Github external
if (typeof config === 'function') {
                config = { provider: { constructor: config } };
            }

            const name = config.name || '_default';
            Hoek.assert(!this.caches.has(name), 'Cannot configure the same cache more than once: ', name === '_default' ? 'default cache' : name);

            let client = null;

            if (config.provider) {
                let provider = config.provider;
                if (typeof provider === 'function') {
                    provider = { constructor: provider };
                }

                client = new Catbox.Client(provider.constructor, provider.options || { partition: 'hapi-cache' });
            }
            else {
                client = new Catbox.Client(config.engine);
            }

            this.caches.set(name, { client, segments: {}, shared: config.shared || false });
            added.push(client);
        }

        return added;
    }
github hapijs / hapi / lib / core.js View on Github external
_cachePolicy(options, _segment, realm) {

        options = Config.apply('cachePolicy', options);

        const plugin = realm && realm.plugin;
        const segment = options.segment || _segment || (plugin ? `!${plugin}` : '');
        Hoek.assert(segment, 'Missing cache segment name');

        const cacheName = options.cache || '_default';
        const cache = this.caches.get(cacheName);
        Hoek.assert(cache, 'Unknown cache', cacheName);
        Hoek.assert(!cache.segments[segment] || cache.shared || options.shared, 'Cannot provision the same cache segment more than once');
        cache.segments[segment] = true;

        return new Catbox.Policy(options, cache.client, segment);
    }

@hapi/catbox

Multi-strategy object caching service

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis

Popular @hapi/catbox functions