Tuang
09/29/2019, 4:17 AMimport java.time.Duratio
class SimpleObjectCache (val cacheDuration: Duration) {
private val cacheManager = if (cacheDuration.getSeconds().toInt() <= 2147483647) SimpleObjectCacheManager(cacheDuration.getSeconds().toInt()) else throw IllegalArgumentException("cacheDuration Int value is out of range")
It is simple, i hope you got what i m doing is.
cacheManger
is too long right? 😁
Is there any better way? 🤔Kirill Zhukov
09/29/2019, 4:38 AMSimpleObjectCacheManager
accept Duration
in the constructor.
class SimpleObjectCache(val cacheDuration: Duration) {
private val DURATION_THRESHOLD = Duration.ofSeconds(2147483647)
private val cacheManager: SimpleObjectCacheManager =
if (cacheDuration <= DURATION_THRESHOLD) SimpleObjectCacheManager(cacheDuration)
else error("cacheDuration Int value is out of range")
}
Kirill Zhukov
09/29/2019, 4:39 AMrequire
on initializationKirill Zhukov
09/29/2019, 4:40 AMclass SimpleObjectCache(cacheDuration: Duration) {
init {
require(cacheDuration <= DURATION_THRESHOLD) { "cacheDuration Int value is out of range" }
}
private companion object {
val DURATION_THRESHOLD = Duration.ofSeconds(2147483647)
}
private val cacheManager = SimpleObjectCacheManager(cacheDuration)
}
Tuang
09/29/2019, 4:49 AM