-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract session cache building into a factory + bump core and tests (#…
…192) * Extract session cache building into a factory + bump core and tests * Update src/jvmMain/kotlin/controller/validation/GuavaSessionCacheAdapter.kt Co-authored-by: Dylan Hall <[email protected]> --------- Co-authored-by: Dylan Hall <[email protected]>
- Loading branch information
Showing
7 changed files
with
80 additions
and
27 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
7 changes: 7 additions & 0 deletions
7
src/jvmMain/kotlin/controller/validation/SessionCacheFactory.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,7 @@ | ||
package controller.validation | ||
|
||
import org.hl7.fhir.validation.cli.services.SessionCache | ||
|
||
interface SessionCacheFactory { | ||
fun getSessionCache(): SessionCache | ||
} |
49 changes: 49 additions & 0 deletions
49
src/jvmMain/kotlin/controller/validation/SessionCacheFactoryImpl.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,49 @@ | ||
package controller.validation | ||
|
||
import org.hl7.fhir.validation.cli.services.PassiveExpiringSessionCache | ||
import org.hl7.fhir.validation.cli.services.SessionCache | ||
import java.util.concurrent.TimeUnit | ||
|
||
private const val SESSION_CACHE_DURATION_ENV_KEY = "SESSION_CACHE_DURATION" | ||
private const val SESSION_DEFAULT_DURATION: Long = 60 | ||
|
||
private const val SESSION_CACHE_SIZE_ENV_KEY = "SESSION_CACHE_SIZE" | ||
private const val SESSION_DEFAULT_SIZE: Long = 4 | ||
|
||
private const val SESSION_CACHE_IMPLEMENTATION_ENV_KEY = "SESSION_CACHE_IMPLEMENTATION" | ||
|
||
private const val GUAVA_SESSION_CACHE_IMPLEMENTATION = "GuavaSessionCacheAdapter" | ||
private const val PASSIVE_EXPIRING_SESSION_CACHE_IMPLEMENTATION = "PassiveExpiringSessionCache" | ||
|
||
private const val SESSION_DEFAULT_CACHE_IMPLEMENTATION: String = GUAVA_SESSION_CACHE_IMPLEMENTATION | ||
|
||
class SessionCacheFactoryImpl : SessionCacheFactory { | ||
|
||
override fun getSessionCache(): SessionCache { | ||
/* Session cache configuration from environment variables. | ||
* | ||
* SESSION_CACHE_IMPLEMENTATION can be either the deprecated PassiveExpiringSessionCache or the preferred | ||
* GuavaSessionCacheAdapter, and will be GuavaSessionCacheAdapter if unspecified. | ||
* | ||
* SESSION_CACHE_DURATION is the duration in minutes that a session will be kept in the cache. If negative, | ||
* sessions will not expire. If unspecified, the default is 60 minutes. | ||
* | ||
* SESSION_CACHE_SIZE (only available in GuavaSessionCacheAdapter) is the maximum number of sessions that will | ||
* be kept in the cache in last accessed last out order. If unspecified, the default is 4. | ||
* | ||
* TODO this should be encapsulated in a session cache configuration class, and use a cleaner method of | ||
* configuration. These env vars are overloaded, and should be split per cache implementation. | ||
*/ | ||
val sessionCacheDuration = System.getenv(SESSION_CACHE_DURATION_ENV_KEY)?.toLong() ?: SESSION_DEFAULT_DURATION; | ||
val sessionCacheSize = System.getenv(SESSION_CACHE_SIZE_ENV_KEY)?.toLong() ?: SESSION_DEFAULT_SIZE | ||
val sessionCacheImplementation = | ||
System.getenv(SESSION_CACHE_IMPLEMENTATION_ENV_KEY) ?: SESSION_DEFAULT_CACHE_IMPLEMENTATION; | ||
val sessionCache: SessionCache = | ||
if (sessionCacheImplementation == PASSIVE_EXPIRING_SESSION_CACHE_IMPLEMENTATION) { | ||
PassiveExpiringSessionCache(sessionCacheDuration, TimeUnit.MINUTES).setResetExpirationAfterFetch(true); | ||
} else { | ||
GuavaSessionCacheAdapter(sessionCacheSize, sessionCacheDuration) | ||
} | ||
return sessionCache | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#Generated by the Semver Plugin for Gradle | ||
#Thu Aug 29 22:33:32 UTC 2024 | ||
#Mon Sep 23 16:48:02 UTC 2024 | ||
version.buildmeta= | ||
version.major=1 | ||
version.minor=0 | ||
version.patch=56 | ||
version.patch=57 | ||
version.prerelease=SNAPSHOT | ||
version.semver=1.0.56-SNAPSHOT | ||
version.semver=1.0.57-SNAPSHOT |