-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (26 loc) · 904 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
/**
* cache/index.js
* Entry point to cache module
*/
const Collection = require('./lib/Collection');
function Cache(options) {
const collections = {};
const gc = function getCollection(collectionName) {
const collection = this._collections[collectionName];
if (collection) {
return collection;
}
throw new Error(`No cache collection ${collectionName} registered`);
}.bind({ _collections: collections });
gc._options = options;
gc._collections = collections;
Object.setPrototypeOf(gc, Cache.prototype);
return gc;
}
Cache.prototype.create = function createCache(collectionName, options) {
if (this._collections[collectionName]) {
throw new Error(`Cache collection ${collectionName} already exists`);
}
this._collections[collectionName] = new Collection(collectionName, options);
};
module.exports = Cache;