-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.js
29 lines (27 loc) · 824 Bytes
/
index.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
const { Cache } = require('./src/cache')
const createStorage = require('./src/storage')
/**
* @param {!Object} options
* @param {!Object} [options.storage] - the storage to use; default is `{ type: 'memory' }`
* @param {?number} [options.ttl=0] - in seconds; default is 0 seconds, so it only does dedupe without cache
* @param {?function} options.onDedupe
* @param {?function} options.onHit
* @param {?function} options.onMiss
*/
function createCache (options) {
if (!options) {
options = { storage: { type: 'memory' } }
} else if (!options.storage) {
options.storage = { type: 'memory' }
}
const storage = createStorage(options.storage.type, options.storage.options)
return new Cache({
...options,
storage
})
}
module.exports = {
Cache,
createCache,
createStorage
}