aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactoryWithCache.kt
blob: 0b56e174f91d1a45f3868c3db865777cbae405fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.base.resolvers.external

import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
import java.util.concurrent.ConcurrentHashMap

public class ExternalLocationProviderFactoryWithCache(
    public val ext: ExternalLocationProviderFactory
) : ExternalLocationProviderFactory {

    private val locationProviders = ConcurrentHashMap<ExternalDocumentation, CacheWrapper>()

    override fun getExternalLocationProvider(doc: ExternalDocumentation): ExternalLocationProvider? =
        locationProviders.getOrPut(doc) { CacheWrapper(ext.getExternalLocationProvider(doc)) }.provider

    private class CacheWrapper(val provider: ExternalLocationProvider?)
}