import { NpmRegistry } from './smartnpm.classes.npmregistry'; import * as plugins from './smartnpm.plugins'; export class RegistryCache { npmregistryRef: NpmRegistry; public levelCache: plugins.levelcache.LevelCache; constructor(npmRegistryRefArg: NpmRegistry) { this.npmregistryRef = npmRegistryRefArg; this.levelCache = new plugins.levelcache.LevelCache({ cacheId: encodeURIComponent(this.npmregistryRef.options.npmRegistryUrl), }); } public async getCachedFile (fileId: string): Promise { const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(fileId); if (cacheEntry) { return plugins.smartfile.Smartfile.fromFoldedJson(cacheEntry.contents.toString()); } return null; } public async cacheSmartFile (fileIdArg: string, smartfileArg: plugins.smartfile.Smartfile) { await this.levelCache.storeCacheEntryByKey(fileIdArg, new plugins.levelcache.CacheEntry({ contents: Buffer.from(smartfileArg.foldToJson()), ttl: 60000 })); } }