-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement a request cache for mutation and insertion queries #137
Also make sure to invalidate the cache when SILO has a new data version
- Loading branch information
1 parent
8313996
commit 17ff89c
Showing
9 changed files
with
304 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
lapis2/src/main/kotlin/org/genspectrum/lapis/scheduler/DataVersionCacheInvalidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.genspectrum.lapis.scheduler | ||
|
||
import mu.KotlinLogging | ||
import org.genspectrum.lapis.silo.CachedSiloClient | ||
import org.genspectrum.lapis.silo.SILO_QUERY_CACHE_NAME | ||
import org.springframework.cache.annotation.CacheEvict | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Component | ||
import java.util.concurrent.TimeUnit | ||
|
||
private val log = KotlinLogging.logger {} | ||
|
||
@Component | ||
class DataVersionCacheInvalidator( | ||
private val cachedSiloClient: CachedSiloClient, | ||
private val cacheClearer: CacheClearer, | ||
) { | ||
private var currentlyCachedDataVersion = "uninitialized" | ||
|
||
@Scheduled(fixedRate = 1, timeUnit = TimeUnit.SECONDS) | ||
@Synchronized | ||
fun invalidateSiloCache() { | ||
log.debug { "checking for data version change" } | ||
|
||
val info = cachedSiloClient.callInfo() | ||
if (info.dataVersion != currentlyCachedDataVersion) { | ||
log.info { | ||
"Invalidating cache, old data version: $currentlyCachedDataVersion, " + | ||
"new data version: ${info.dataVersion}" | ||
} | ||
cacheClearer.clearCache() | ||
currentlyCachedDataVersion = info.dataVersion | ||
} | ||
} | ||
} | ||
|
||
@Component | ||
class CacheClearer { | ||
@CacheEvict(SILO_QUERY_CACHE_NAME, allEntries = true) | ||
fun clearCache() { | ||
log.info { "Clearing cache $SILO_QUERY_CACHE_NAME" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.