当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript cache-manager.caching函数代码示例

本文整理汇总了TypeScript中cache-manager.caching函数的典型用法代码示例。如果您正苦于以下问题:TypeScript caching函数的具体用法?TypeScript caching怎么用?TypeScript caching使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了caching函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: register

register('memory', (config, logger) => {
  const options = {
    store: 'memory',
    max: config.max,
    maxAge: config.maxAge,
    dispose: config.dispose,
    length: config.length,
    stale: config.stale,
    ttl: config.ttl,
  };
  return cacheManager.caching(options);
});
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:12,代码来源:index.ts

示例2: getUser

import * as cacheManager from 'cache-manager'

const memoryCache = cacheManager.caching({ store: 'memory', max: 100, ttl: 10/*seconds*/ });
const ttl = 5;

memoryCache.set('foo', 'bar', { ttl: ttl }, (err) => {

    if (err) {
        throw err;
    }

    memoryCache.get('foo', (err, result) => {

        // console.log(result);

        memoryCache.del('foo', (err) => {
        });

    });
});

function getUser(id: number, cb: Function) {

    cb(null, { id: id, name: 'Bob' });
}

const userId = 123;
const key = 'user_' + userId;

// Note: ttl is optional in wrap()
memoryCache.wrap<{ id: number, name: string }>(key, (cb) => {
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:cache-manager-tests.ts

示例3: require

import Logger from 'bunyan'
import cacheManager from 'cache-manager'
import express from 'express'
import {Application, WebhookEvent} from './application'
import {Context} from './context'
import {createApp} from './github-app'
import {logger} from './logger'
import {resolve} from './resolver'
import {createServer} from './server'
import {createWebhookProxy} from './webhook-proxy'

const Webhooks = require('@octokit/webhooks')
const logRequestErrors = require('./middleware/log-request-errors')

const cache = cacheManager.caching({
  store: 'memory',
  ttl: 60 * 60 // 1 hour
})

const defaultApps = [
  require('./plugins/sentry'),
  require('./plugins/stats'),
  require('./plugins/default')
]

export class Probot {
  public server: express.Application
  public webhook: any
  public logger: Logger

  private options: Options
  private apps: Application[]
开发者ID:brntbeer,项目名称:probot,代码行数:32,代码来源:index.ts


注:本文中的cache-manager.caching函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。