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:
@@ -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.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user