Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session config #158

Merged
merged 7 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create service function
  • Loading branch information
rpassas committed Dec 6, 2023
commit 291e12571f20c09554fdce01019cf2c9e6bb9a31
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ private const val MIN_FREE_MEMORY = 250000000
private const val SESSION_DEFAULT_DURATION: Long = 60

class ValidationServiceFactoryImpl : ValidationServiceFactory {
private val sessionCacheDuration: Long
private var sessionCache: SessionCache
private var validationService: ValidationService

init {
sessionCacheDuration = System.getenv("SESSION_CACHE_DURATION")?.toLong() ?: SESSION_DEFAULT_DURATION;
sessionCache = SessionCache(sessionCacheDuration, TimeUnit.MINUTES);
validationService = createValidationServiceInstance();
}

fun createValidationServiceInstance() : ValidationService {
val sessionCacheDuration = System.getenv("SESSION_CACHE_DURATION")?.toLong() ?: SESSION_DEFAULT_DURATION;
val sessionCache = SessionCache(sessionCacheDuration, TimeUnit.MINUTES);
sessionCache.setExpirationAfterAccess(true);
validationService = ValidationService(sessionCache);
return ValidationService(sessionCache);
}

override fun getValidationService() : ValidationService {

if (java.lang.Runtime.getRuntime().freeMemory() < MIN_FREE_MEMORY) {
println("Free memory ${java.lang.Runtime.getRuntime().freeMemory()} is less than ${MIN_FREE_MEMORY}. Re-initializing validationService");
sessionCache = SessionCache(sessionCacheDuration, TimeUnit.MINUTES);
sessionCache.setExpirationAfterAccess(true);
validationService = ValidationService(sessionCache);
validationService = createValidationServiceInstance();
}
return validationService;
}
Expand Down
Loading