Merge pull request #4061 from backstage/orkohunter/add-some-caching-to-when-using-urlReader

techdocs-backend: cache docs site when built using urlReader for 30 minutes
This commit is contained in:
Himanshu Mishra
2021-01-14 12:17:30 +01:00
committed by GitHub
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.`,
);