|
| 1 | +import routeCache = require('route-cache'); |
| 2 | +import IoRedisStore = require('route-cache/ioRedisStore'); |
| 3 | +import LruStore = require('route-cache/lruStore'); |
| 4 | +import * as express from 'express'; |
| 5 | +import Redis from 'ioredis'; |
| 6 | + |
| 7 | +const redis = new Redis(); |
| 8 | +const ioRedisStore: IoRedisStore = new IoRedisStore(redis); |
| 9 | +const lruStore: LruStore = new LruStore({ max: 100, length: (value: any, key: string) => 1, maxAge: 1000 }); |
| 10 | + |
| 11 | +const configRedisStore: routeCache.ConfigOptions = { max: 100, cacheStore: ioRedisStore }; |
| 12 | +const configLruStore: routeCache.ConfigOptions = { max: 100, cacheStore: lruStore }; |
| 13 | + |
| 14 | +const cacheKeyFunc: routeCache.CacheKeyFunc = (req: express.Request, res: express.Response) => 'foo'; |
| 15 | +const cacheKeyFuncNull: routeCache.CacheKeyFunc = (req: express.Request, res: express.Response) => null; |
| 16 | + |
| 17 | +routeCache.config({ max: 100, cacheStore: ioRedisStore }); // $ExpectType RouteCache |
| 18 | +routeCache.config({ max: 100, cacheStore: lruStore }); // $ExpectType RouteCache |
| 19 | +routeCache.config({ max: 10 }).config({ max: 100 }); // $ExpectType RouteCache |
| 20 | + |
| 21 | +routeCache.config(configRedisStore); // $ExpectType RouteCache |
| 22 | +routeCache.config(configLruStore); // $ExpectType RouteCache |
| 23 | + |
| 24 | +routeCache.config({ max: 100 }).cacheSeconds(10, 'foo'); // $ExpectType RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>> |
| 25 | +routeCache.cacheSeconds(10, cacheKeyFunc); // $ExpectType RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>> |
| 26 | +routeCache.cacheSeconds(10, cacheKeyFuncNull); // $ExpectType RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>> |
| 27 | +routeCache.cacheSeconds(10, 'foo'); // $ExpectType RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>> |
| 28 | + |
| 29 | +routeCache.removeCache('foo'); // $ExpectType void |
| 30 | +routeCache.config({ max: 100 }).removeCache('foo'); // $ExpectType void |
| 31 | + |
| 32 | +routeCache.cacheStore; // $ExpectType Store |
| 33 | +routeCache.config({ max: 100 }).cacheStore; // $ExpectType Store |
| 34 | + |
| 35 | +const app = express(); |
| 36 | +app.use(routeCache.config({ max: 100 }).cacheSeconds(10, 'foo')); // $ExpectType Express |
0 commit comments