2021-04-26 08:30:02 +00:00
|
|
|
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<plugins.smartfile.Smartfile> {
|
|
|
|
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) {
|
2021-04-29 20:44:47 +00:00
|
|
|
if (smartfileArg) {
|
|
|
|
await this.levelCache.storeCacheEntryByKey(fileIdArg, new plugins.levelcache.CacheEntry({
|
|
|
|
contents: Buffer.from(smartfileArg.foldToJson()),
|
|
|
|
ttl: 60000
|
|
|
|
}));
|
|
|
|
}
|
2021-04-26 08:30:02 +00:00
|
|
|
}
|
|
|
|
}
|