How to use the cache-manager.caching function in cache-manager

To help you get started, we’ve selected a few cache-manager 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 dial-once / node-cache-manager-redis / test / lib / redis-store-zlib-spec.js View on Github external
before(function () {
      redisCacheByUrl = require('cache-manager').caching({
        store: redisStore,
        // redis://[:password@]host[:port][/db-number][?option=value]
        url: 'redis://:' + config.redis.auth_pass + '@' + config.redis.host + ':' + config.redis.port + '/' + config.redis.db + '?ttl=' + config.redis.ttl,
        // some fakes to see that url overrides them
        host: 'test-host',
        port: -78,
        db: -7,
        auth_pass: 'test_pass',
        password: 'test_pass',
        ttl: -6,
        compress: true
      });
    });
github flow-typed / flow-typed / definitions / npm / cache-manager_v2.x.x / test_cache-manager_v2.js View on Github external
// @flow
import cacheManager from 'cache-manager';
import type { Cache } from 'cache-manager';

const memoryCache: Cache = new cacheManager.caching({
  store: 'memory', max: 100, ttl: 10
});

// $ExpectError store missing
const invalidMemoryCache: Cache = new cacheManager.caching({
  max: 200,
});

// $ExpectError
const invalidMemoryCache2: Cache = new cacheManager.caching({ max: '200' });

(memoryCache.set('foo', 'bar', { ttl: 5 }): Promise);
// $ExpectError Wrong Promise return
(memoryCache.set('foo', 'bar', { ttl: 5 }): Promise);

memoryCache.get('foo');
github probot / probot / test / apps / helper.ts View on Github external
// FIXME: move this to a test helper that can be used by other apps

import cacheManager from 'cache-manager'
import { Application, ApplicationFunction } from '../../src'

const cache = cacheManager.caching({ store: 'memory', ttl: 0 })

export function newApp (): Application {
  return new Application({ app: {
    getInstallationAccessToken: jest.fn().mockResolvedValue('test'),
    getSignedJsonWebToken: jest.fn().mockReturnValue('test')
  }, cache })
}

export function createApp (appFn?: ApplicationFunction) {
  const app = newApp()
  appFn && appFn(app)
  return app
}
github travisghansen / external-auth-server / src / store.js View on Github external
max: 0,
    ttl: 0
  };
}

// force 0 ttl
cacheOpts.ttl = 0;
console.log("store options: %j", cacheOpts);

switch (cacheOpts.store) {
  case "redis":
    cacheOpts.store = redisStore;
    break;
}

var cache = cacheManager.caching(cacheOpts);

function set(key, val, ttl = 0) {
  ttl = Math.floor(ttl);
  return new Promise((resolve, reject) => {
    cache.set(key, val, { ttl: ttl }, err => {
      if (err) {
        reject(err);
      }
      resolve();
    });
  });
}

function get(key) {
  return new Promise((resolve, reject) => {
    cache.get(key, (err, result) => {
github mcibique / express-security / server / helpers / caching.js View on Github external
import config from 'config';
import extend from 'extend';
import logger from 'logger';
import redisStore from 'cache-manager-redis';

// level 2 cache - redis
let redisConfig = extend({}, config.caching.redis, { store: redisStore });
let redisCache = cacheManager.caching(redisConfig);

redisCache.store.events.on('redisError', function onRedisCacheError(error) {
  logger.error(error);
});

// level 1 cache - memory
let memoryConfig = extend({}, config.caching.memory, { store: 'memory' });
let memoryCache = cacheManager.caching(memoryConfig);

// cache hierarchy wrapper
let multiCache = cacheManager.multiCaching([ memoryCache, redisCache ]);
export default multiCache;
github glacejs / glace-js / lib / proxy / middleware / cache.js View on Github external
inited = new Promise(resolve => {

            var fillcb = null;
            if (CONF.cache.existing) fillcb = resolve;

            diskCache = cacheManager.caching({
                store: fsStore,
                options: {
                    ttl: CONF.cache.ttl,
                    maxsize: CONF.cache.size,
                    path: cacheFolder,
                    preventfill: !CONF.cache.existing,
                    fillcallback: fillcb } });

            if (!CONF.cache.existing) resolve();
        });
    };
github kba / anno-common / anno-server / middleware / acl-metadata.js View on Github external
function cached(metadataEndpoint, collection, context, cb) {
    const cache = (collection in _caches) ? _caches[collection] : cacheManager.caching({
        store: 'memory',
        max: 1000,
        ttl: 60 * 60 * 12
    })
    return cache.wrap(context, function() {
        return new Promise(function(resolve, reject) {
            axios.get(`${metadataEndpoint}?uri=${context}`)
                .then(({data}) => resolve(data))
                .catch(err => reject(err))
        })
    })
}
github prerender / prerender / lib / plugins / s3HtmlCache.js View on Github external
init: function() {
        this.cache = cacheManager.caching({
            store: s3_cache
        });
    },
github sebelga / nsql-cache / lib / index.js View on Github external
            this._stores = this._stores.map(store => nodeCacheManager.caching(store));
            this._cacheManager = nodeCacheManager.multiCaching(this._stores);
github digidem / simple-odk / middlewares / github-auth-passthrough.js View on Github external
var basicAuth = require('basic-auth')
var request = require('request')
var debug = require('debug')('simple-odk:github-auth')
var cacheManager = require('cache-manager')
var createHash = require('../helpers/sha-hash.js')

var authCache = cacheManager.caching({store: 'memory', max: 500, ttl: 300})

request = request.defaults({
  headers: { 'User-Agent': 'simple-odk' }
})

/**
 * Middleware to authenticate against Github using Basic Auth.
 * Github will return status 404 for unauthorized requests
 * https://developer.github.com/v3/auth/#basic-authentication
 * This checks a user/pass is valid against Github and returns
 * 401 to the ODK Collect client if it not
 */
function GithubAuth () {
  return function (req, res, next) {
    var auth = basicAuth(req)
    var t0 = Date.now()

cache-manager

Cache Manager for Node.js

MIT
Latest version published 11 days ago

Package Health Score

91 / 100
Full package analysis

Popular cache-manager functions