21 lines
505 B
JavaScript
21 lines
505 B
JavaScript
const memoryBackend = require("./backend/pricing/memory.js");
|
|
|
|
const globalCache = {};
|
|
let globalInstance;
|
|
|
|
function global({ seed = {}, backend = memoryBackend } = {}) {
|
|
if (!globalInstance) {
|
|
Object.assign(globalCache, seed, { USD: 1 });
|
|
globalInstance = backend(globalCache);
|
|
}
|
|
return globalInstance;
|
|
}
|
|
|
|
function instance({ cache = {}, backend = memoryBackend } = {}) {
|
|
return backend(Object.assign(cache, { USD: 1 }));
|
|
}
|
|
module.exports = {
|
|
global,
|
|
instance,
|
|
};
|