techdocs: cache docs site when built using urlReader for 30 minutes

This caching makes it usable experience, so that docs are not built on every load.
In future readTree will support a method to fetch the timestamp of the latest HEAD. And
it should be used to invalidate the cache.
This commit is contained in:
Himanshu Mishra
2021-01-13 21:08:03 +01:00
parent 9ea0aa9bb4
commit cb7af51e73
2 changed files with 17 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-backend': patch
---
If using Url Reader, cache downloaded source files for 30 minutes.
@@ -144,6 +144,18 @@ export class DocsBuilder {
}
}
// Cache downloaded source files for 30 minutes.
// TODO: When urlReader/readTree supports some way to get latest commit timestamp,
// it should be used to invalidate cache.
if (type === 'url') {
const builtAt = buildMetadataStorage.getTimestamp();
const now = Date.now();
if (builtAt > now - 1800000) {
return true;
}
}
this.logger.debug(
`Docs for entity ${getEntityId(this.entity)} was outdated.`,
);