aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactoryWithCache.kt
blob: 4fa1f391c967141fe5f5f09caa089344ab9f3fdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package org.jetbrains.dokka.base.resolvers.external

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

class ExternalLocationProviderFactoryWithCache(val ext: ExternalLocationProviderFactory) :
    ExternalLocationProviderFactory {

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

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

    private class CacheWrapper(val provider: ExternalLocationProvider?)
}