From 1d5a7cf209937f3b27bd4c222cb1f2ec9258dc25 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Thu, 26 Oct 2023 17:40:03 +0200 Subject: [PATCH] Create a new cache for each site generation This resolves caching issues when generating for multiple branches or when serving continuously. --- .../structurizr/site/generatr/site/DiagramGenerator.kt | 9 ++++++--- .../structurizr/site/generatr/site/SiteGenerator.kt | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/DiagramGenerator.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/DiagramGenerator.kt index 50f2d2c1..83e13e5e 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/DiagramGenerator.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/DiagramGenerator.kt @@ -36,9 +36,12 @@ fun generateDiagrams(workspace: Workspace, exportDir: File) { } } -private val diagramCache = ConcurrentHashMap() - -fun generateDiagramWithElementLinks(workspace: Workspace, view: View, url: String): String { +fun generateDiagramWithElementLinks( + workspace: Workspace, + view: View, + url: String, + diagramCache: ConcurrentHashMap +): String { val diagram = generatePlantUMLDiagramWithElementLinks(workspace, view, url) val name = "${diagram.key}-${view.key}" diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt index 9dd41dca..c97037f0 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt @@ -10,6 +10,7 @@ import java.io.File import java.math.BigInteger import java.nio.file.Path import java.security.MessageDigest +import java.util.concurrent.ConcurrentHashMap fun copySiteWideAssets(exportDir: File) { copySiteWideAsset(exportDir, "/css/style.css") @@ -62,8 +63,9 @@ fun generateSite( serving: Boolean = false ) { val generatorContext = GeneratorContext(version, workspace, branches, currentBranch, serving) { key, url -> + val diagramCache = ConcurrentHashMap() workspace.views.views.singleOrNull { view -> view.key == key } - ?.let { generateDiagramWithElementLinks(workspace, it, url) } + ?.let { generateDiagramWithElementLinks(workspace, it, url, diagramCache) } } val branchDir = File(exportDir, currentBranch)