-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
42 lines (33 loc) · 1.19 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {createVbbHafas as createHafas} from 'vbb-hafas'
import {createCachedHafasClient as withCache} from './index.js'
// using Redis
import Redis from 'ioredis'
import {createRedisStore} from './stores/redis.js'
const db = new Redis()
const store = createRedisStore(db)
const MINUTE = 60 * 1000
// using SQLite
// import sqlite3 from 'sqlite3'
// import {createSqliteStore} from './stores/sqlite.js'
// const db = new sqlite3.Database(':memory:')
// const store = createSqliteStore(db)
const wollinerStr = '900007105'
const husemannstr = '900110511'
const when = new Date(Date.now() + 60 * MINUTE)
const hafas = createHafas('cached-hafas-client example')
const cachedHafas = withCache(hafas, store)
cachedHafas.on('hit', (method, ...args) => console.info('cache hit!', method, ...args))
cachedHafas.on('miss', (method, ...args) => console.info('cache miss!', method, ...args))
await cachedHafas.departures(wollinerStr, {
duration: 10, when
})
const {
departures: deps,
} = await cachedHafas.departures(wollinerStr, {
duration: 3, when: new Date(+when + 3 * MINUTE)
})
console.log(deps[0])
await cachedHafas.stop(wollinerStr)
const stop = await cachedHafas.stop(wollinerStr)
console.log(stop)
db.quit()