MCPcopy
hub / github.com/hapijs/hapi / _createCache

Method _createCache

lib/core.js:207–247  ·  view source on GitHub ↗
(configs)

Source from the content-addressed store, hash-verified

205 }
206
207 _createCache(configs) {
208
209 Hoek.assert(this.phase !== 'initializing', 'Cannot provision server cache while server is initializing');
210
211 configs = Config.apply('cache', configs);
212
213 const added = [];
214 for (let config of configs) {
215
216 // <function>
217 // { provider: <function> }
218 // { provider: { constructor: <function>, options } }
219 // { engine }
220
221 if (typeof config === 'function') {
222 config = { provider: { constructor: config } };
223 }
224
225 const name = config.name ?? '_default';
226 Hoek.assert(!this.caches.has(name), 'Cannot configure the same cache more than once: ', name === '_default' ? 'default cache' : name);
227
228 let client = null;
229
230 if (config.provider) {
231 let provider = config.provider;
232 if (typeof provider === 'function') {
233 provider = { constructor: provider };
234 }
235
236 client = new Catbox.Client(provider.constructor, provider.options ?? { partition: 'hapi-cache' });
237 }
238 else {
239 client = new Catbox.Client(config.engine);
240 }
241
242 this.caches.set(name, { client, segments: {}, shared: config.shared ?? false });
243 added.push(client);
244 }
245
246 return added;
247 }
248
249 registerServer(server) {
250

Callers 2

_initializeCacheMethod · 0.80
server.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected