Loading app-common/src/main/kotlin/net/thunderbird/app/common/account/AccountCreator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ internal class AccountCreator( } } private fun create(account: Account): String { private suspend fun create(account: Account): String { val newAccount = preferences.newAccount(account.uuid) newAccount.email = account.emailAddress Loading core/android/account/src/main/kotlin/net/thunderbird/core/android/account/LegacyAccount.kt +0 −4 Original line number Diff line number Diff line Loading @@ -163,10 +163,6 @@ open class LegacyAccount( @set:Synchronized var inboxFolderId: Long? = null @get:Synchronized @set:Synchronized var outboxFolderId: Long? = null @get:Synchronized @set:Synchronized var draftsFolderId: Long? = null Loading core/android/account/src/main/kotlin/net/thunderbird/core/android/account/LegacyAccountWrapper.kt +0 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,6 @@ data class LegacyAccountWrapper( val importedArchiveFolder: String? = null, val importedSpamFolder: String? = null, val inboxFolderId: Long? = null, val outboxFolderId: Long? = null, val draftsFolderId: Long? = null, val sentFolderId: Long? = null, val trashFolderId: Long? = null, Loading core/android/account/src/test/kotlin/net/thunderbird/core/android/account/LegacyAccountWrapperTest.kt +0 −1 Original line number Diff line number Diff line Loading @@ -127,7 +127,6 @@ class LegacyAccountWrapperTest { importedArchiveFolder = null, importedSpamFolder = null, inboxFolderId = null, outboxFolderId = null, draftsFolderId = null, sentFolderId = null, trashFolderId = null, Loading core/common/src/commonMain/kotlin/net/thunderbird/core/common/cache/TimeLimitedCache.kt 0 → 100644 +62 −0 Original line number Diff line number Diff line @file:OptIn(ExperimentalTime::class) package net.thunderbird.core.common.cache import kotlin.time.Clock import kotlin.time.Duration import kotlin.time.Duration.Companion.hours import kotlin.time.ExperimentalTime import kotlin.time.Instant class TimeLimitedCache<TKey : Any, TValue : Any?>( private val clock: Clock = Clock.System, private val cache: MutableMap<TKey, Entry<TValue>> = mutableMapOf(), ) : Cache<TKey, TimeLimitedCache.Entry<TValue>> { companion object { private val DEFAULT_EXPIRATION_TIME = 1.hours } override fun get(key: TKey): Entry<TValue>? { recycle(key) return cache[key] } fun getValue(key: TKey): TValue? = get(key)?.value fun set(key: TKey, value: TValue, expiresIn: Duration = DEFAULT_EXPIRATION_TIME) { set(key, Entry(value, creationTime = clock.now(), expiresIn)) } override fun set(key: TKey, value: Entry<TValue>) { cache[key] = value } override fun hasKey(key: TKey): Boolean { recycle(key) return key in cache } override fun clear() { cache.clear() } fun clearExpired() { cache.entries.removeAll { (_, entry) -> entry.expiresAt < clock.now() } } private fun recycle(key: TKey) { val entry = cache[key] ?: return if (entry.expiresAt < clock.now()) { cache.remove(key) } } data class Entry<TValue : Any?>( val value: TValue, val creationTime: Instant, val expiresIn: Duration, val expiresAt: Instant = creationTime + expiresIn, ) } Loading
app-common/src/main/kotlin/net/thunderbird/app/common/account/AccountCreator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ internal class AccountCreator( } } private fun create(account: Account): String { private suspend fun create(account: Account): String { val newAccount = preferences.newAccount(account.uuid) newAccount.email = account.emailAddress Loading
core/android/account/src/main/kotlin/net/thunderbird/core/android/account/LegacyAccount.kt +0 −4 Original line number Diff line number Diff line Loading @@ -163,10 +163,6 @@ open class LegacyAccount( @set:Synchronized var inboxFolderId: Long? = null @get:Synchronized @set:Synchronized var outboxFolderId: Long? = null @get:Synchronized @set:Synchronized var draftsFolderId: Long? = null Loading
core/android/account/src/main/kotlin/net/thunderbird/core/android/account/LegacyAccountWrapper.kt +0 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,6 @@ data class LegacyAccountWrapper( val importedArchiveFolder: String? = null, val importedSpamFolder: String? = null, val inboxFolderId: Long? = null, val outboxFolderId: Long? = null, val draftsFolderId: Long? = null, val sentFolderId: Long? = null, val trashFolderId: Long? = null, Loading
core/android/account/src/test/kotlin/net/thunderbird/core/android/account/LegacyAccountWrapperTest.kt +0 −1 Original line number Diff line number Diff line Loading @@ -127,7 +127,6 @@ class LegacyAccountWrapperTest { importedArchiveFolder = null, importedSpamFolder = null, inboxFolderId = null, outboxFolderId = null, draftsFolderId = null, sentFolderId = null, trashFolderId = null, Loading
core/common/src/commonMain/kotlin/net/thunderbird/core/common/cache/TimeLimitedCache.kt 0 → 100644 +62 −0 Original line number Diff line number Diff line @file:OptIn(ExperimentalTime::class) package net.thunderbird.core.common.cache import kotlin.time.Clock import kotlin.time.Duration import kotlin.time.Duration.Companion.hours import kotlin.time.ExperimentalTime import kotlin.time.Instant class TimeLimitedCache<TKey : Any, TValue : Any?>( private val clock: Clock = Clock.System, private val cache: MutableMap<TKey, Entry<TValue>> = mutableMapOf(), ) : Cache<TKey, TimeLimitedCache.Entry<TValue>> { companion object { private val DEFAULT_EXPIRATION_TIME = 1.hours } override fun get(key: TKey): Entry<TValue>? { recycle(key) return cache[key] } fun getValue(key: TKey): TValue? = get(key)?.value fun set(key: TKey, value: TValue, expiresIn: Duration = DEFAULT_EXPIRATION_TIME) { set(key, Entry(value, creationTime = clock.now(), expiresIn)) } override fun set(key: TKey, value: Entry<TValue>) { cache[key] = value } override fun hasKey(key: TKey): Boolean { recycle(key) return key in cache } override fun clear() { cache.clear() } fun clearExpired() { cache.entries.removeAll { (_, entry) -> entry.expiresAt < clock.now() } } private fun recycle(key: TKey) { val entry = cache[key] ?: return if (entry.expiresAt < clock.now()) { cache.remove(key) } } data class Entry<TValue : Any?>( val value: TValue, val creationTime: Instant, val expiresIn: Duration, val expiresAt: Instant = creationTime + expiresIn, ) }