From ea53a021267f210dddcc0ab03531dea5b0a79bef Mon Sep 17 00:00:00 2001 From: malazalkoj Date: Tue, 25 Jun 2024 12:06:43 +0200 Subject: [PATCH] Remove unnecessary CacheConfig and related classes. --- .../brukertilgang/BrukertilgangService.kt | 6 --- .../no/nav/syfo/config/ApplicationConfig.kt | 21 ---------- .../kotlin/no/nav/syfo/config/CacheConfig.kt | 39 ------------------- .../kotlin/no/nav/syfo/config/RedisConfig.kt | 34 ---------------- .../kotlin/no/nav/syfo/ereg/EregClient.kt | 11 +----- .../no/nav/syfo/kontaktinfo/KrrClient.kt | 2 - .../syfo/narmesteleder/NarmesteLederClient.kt | 7 ---- 7 files changed, 1 insertion(+), 119 deletions(-) delete mode 100644 src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt delete mode 100644 src/main/kotlin/no/nav/syfo/config/CacheConfig.kt delete mode 100644 src/main/kotlin/no/nav/syfo/config/RedisConfig.kt diff --git a/src/main/kotlin/no/nav/syfo/brukertilgang/BrukertilgangService.kt b/src/main/kotlin/no/nav/syfo/brukertilgang/BrukertilgangService.kt index 69286a8..1b13ad8 100644 --- a/src/main/kotlin/no/nav/syfo/brukertilgang/BrukertilgangService.kt +++ b/src/main/kotlin/no/nav/syfo/brukertilgang/BrukertilgangService.kt @@ -1,7 +1,6 @@ package no.nav.syfo.brukertilgang import org.springframework.beans.factory.annotation.Autowired -import org.springframework.cache.annotation.Cacheable import org.springframework.stereotype.Service @Service @@ -9,11 +8,6 @@ class BrukertilgangService @Autowired constructor( private var brukertilgangClient: BrukertilgangClient ) { - @Cacheable( - cacheNames = ["tilgangtilident"], - key = "#innloggetIdent.concat(#oppslaattFnr)", - condition = "#innloggetIdent != null && #oppslaattFnr != null" - ) fun tilgangTilOppslattIdent(innloggetIdent: String, oppslaattFnr: String): Boolean { return oppslaattFnr == innloggetIdent || brukertilgangClient.hasAccessToAnsatt(oppslaattFnr) } diff --git a/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt b/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt deleted file mode 100644 index 20e2e06..0000000 --- a/src/main/kotlin/no/nav/syfo/config/ApplicationConfig.kt +++ /dev/null @@ -1,21 +0,0 @@ -package no.nav.syfo.config - -import org.springframework.cache.annotation.EnableCaching -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.scheduling.annotation.EnableScheduling -import org.springframework.transaction.annotation.EnableTransactionManagement -import org.springframework.web.client.RestTemplate - -@Configuration -@EnableTransactionManagement -@EnableScheduling -@EnableCaching - -class ApplicationConfig { - - @Bean(name = ["scheduler"]) - fun restTemplateScheduler(): RestTemplate { - return RestTemplate() - } -} diff --git a/src/main/kotlin/no/nav/syfo/config/CacheConfig.kt b/src/main/kotlin/no/nav/syfo/config/CacheConfig.kt deleted file mode 100644 index 6268790..0000000 --- a/src/main/kotlin/no/nav/syfo/config/CacheConfig.kt +++ /dev/null @@ -1,39 +0,0 @@ -package no.nav.syfo.config - -import org.springframework.cache.CacheManager -import org.springframework.cache.annotation.EnableCaching -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Profile -import org.springframework.data.redis.cache.RedisCacheConfiguration -import org.springframework.data.redis.cache.RedisCacheManager -import org.springframework.data.redis.cache.RedisCacheWriter -import org.springframework.data.redis.connection.RedisConnectionFactory -import java.time.Duration - -@Configuration -@EnableCaching -@Profile("remote") - -class CacheConfig { - companion object { - const val CACHENAME_EREG_VIRKSOMHETSNAVN: String = "virksomhetsnavn" - } - - @Bean - fun cacheManager(redisConnectionFactory: RedisConnectionFactory): CacheManager { - // create a map of cache names and their configurations - val cacheConfiguration: MutableMap = HashMap() - - - val defaultConfig: RedisCacheConfiguration = RedisCacheConfiguration - .defaultCacheConfig() - .entryTtl(Duration.ofHours(1L)) - cacheConfiguration[CACHENAME_EREG_VIRKSOMHETSNAVN] = defaultConfig - - return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)) - .cacheDefaults(defaultConfig) - .withInitialCacheConfigurations(cacheConfiguration) - .build() - } -} diff --git a/src/main/kotlin/no/nav/syfo/config/RedisConfig.kt b/src/main/kotlin/no/nav/syfo/config/RedisConfig.kt deleted file mode 100644 index 4a3b39b..0000000 --- a/src/main/kotlin/no/nav/syfo/config/RedisConfig.kt +++ /dev/null @@ -1,34 +0,0 @@ -package no.nav.syfo.config - -import io.lettuce.core.RedisURI -import org.springframework.beans.factory.annotation.Value -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.data.redis.connection.RedisStandaloneConfiguration -import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory -import java.net.URI - - -@Configuration -class RedisConfig { - @Bean - fun redisConnectionFactory( - @Value("\${spring.data.redis.url}") url: URI, - @Value("\${spring.data.redis.password}") password: String, - @Value("\${spring.data.redis.username}") username: String, - ): LettuceConnectionFactory { - val redisURI = RedisURI.create(url) - return LettuceConnectionFactory( - RedisStandaloneConfiguration(url.host, url.port).apply { - setUsername(username) - setPassword(password) - database = redisURI.database - }, LettuceClientConfiguration.builder().apply { - if (redisURI.isSsl) { - useSsl() - } - }.build() - ) - } -} diff --git a/src/main/kotlin/no/nav/syfo/ereg/EregClient.kt b/src/main/kotlin/no/nav/syfo/ereg/EregClient.kt index c10c5c4..0e3c586 100644 --- a/src/main/kotlin/no/nav/syfo/ereg/EregClient.kt +++ b/src/main/kotlin/no/nav/syfo/ereg/EregClient.kt @@ -1,16 +1,13 @@ package no.nav.syfo.ereg import javax.inject.Inject -import no.nav.syfo.config.CacheConfig import no.nav.syfo.metric.Metrikk import no.nav.syfo.util.APP_CONSUMER_ID import no.nav.syfo.util.NAV_CALL_ID_HEADER import no.nav.syfo.util.NAV_CONSUMER_ID_HEADER import no.nav.syfo.util.createCallId import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value -import org.springframework.cache.annotation.Cacheable import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -23,11 +20,10 @@ import org.springframework.web.client.RestTemplate class EregClient @Inject constructor( @Value("\${ereg.url}") private val baseUrl: String, private val metric: Metrikk, - @param:Qualifier("scheduler") private val restTemplate: RestTemplate, ) { fun eregResponse(virksomhetsnummer: String): EregOrganisasjonResponse { try { - val response = restTemplate.exchange( + val response = RestTemplate().exchange( getEregUrl(), HttpMethod.GET, entity(), @@ -47,11 +43,6 @@ class EregClient @Inject constructor( } } - @Cacheable( - value = [CacheConfig.CACHENAME_EREG_VIRKSOMHETSNAVN], - key = "#virksomhetsnummer", - condition = "#virksomhetsnummer != null", - ) fun virksomhetsnavn(virksomhetsnummer: String): String { return eregResponse(virksomhetsnummer).navn() } diff --git a/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt b/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt index af2cf7b..68c274e 100644 --- a/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt +++ b/src/main/kotlin/no/nav/syfo/kontaktinfo/KrrClient.kt @@ -7,7 +7,6 @@ import no.nav.syfo.util.NAV_PERSONIDENT_HEADER import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value -import org.springframework.cache.annotation.Cacheable import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -25,7 +24,6 @@ class KrrClient @Autowired constructor( @Value("\${krr.scope}") private val krrScope: String, @Value("\${krr.url}") val krrUrl: String, ) { - @Cacheable(cacheNames = ["krr_fnr"], key = "#fnr", condition = "#fnr != null") fun kontaktinformasjon(fnr: String): DigitalKontaktinfo { val accessToken = "Bearer ${azureAdTokenConsumer.getSystemToken(krrScope)}" val response = RestTemplate().exchange( diff --git a/src/main/kotlin/no/nav/syfo/narmesteleder/NarmesteLederClient.kt b/src/main/kotlin/no/nav/syfo/narmesteleder/NarmesteLederClient.kt index b78f5c4..48536fb 100644 --- a/src/main/kotlin/no/nav/syfo/narmesteleder/NarmesteLederClient.kt +++ b/src/main/kotlin/no/nav/syfo/narmesteleder/NarmesteLederClient.kt @@ -9,7 +9,6 @@ import no.nav.syfo.util.NAV_PERSONIDENT_HEADER import no.nav.syfo.util.bearerHeader import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value -import org.springframework.cache.annotation.Cacheable import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -27,7 +26,6 @@ class NarmesteLederClient( private val tokenDingsConsumer: TokenDingsConsumer, private val contextHolder: TokenValidationContextHolder, ) { - @Cacheable(value = ["aktive_ledere"], key = "#ansattFnr", condition = "#ansattFnr != null") fun alleLedereForSykmeldt( ansattFnr: String, ): List { @@ -53,11 +51,6 @@ class NarmesteLederClient( } } - @Cacheable( - value = ["aktive_ansatte"], - key = "{#ansattFnr, #virksomhetsnummer}", - condition = "{#ansattFnr != null, #virksomhetsnummer != null}" - ) fun aktivNarmesteLederIVirksomhet( ansattFnr: String, virksomhetsnummer: String,