lib/cache.js
/**
* Cache provider for this module.
* Various cache types are available, we default to using "leveldown" via the Level library.
*/
import CacheLevel from './cache/cacheLevel.js';
/**
* Set the global cache instance
*/
let CacheInstance = null;
/**
* Create a new Cache Instance.
* This function should only be called once for the lifetime of the module.
*/
async function createCacheInstance() {
return new CacheLevel();
}
/**
* Get the configured Cache implementation
*/
export async function getCache() {
if (CacheInstance === null) {
CacheInstance = await createCacheInstance();
}
return CacheInstance;
}
export default {
getCache,
};