本文整理汇总了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);
});
示例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) => {
示例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[]