Move Cache to core common module
This commit is contained in:
parent
fab0749abd
commit
59541c0d6b
6 changed files with 19 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
package com.fsck.k9.cache
|
||||
package app.k9mail.core.common.cache
|
||||
|
||||
interface Cache<KEY : Any, VALUE : Any> {
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.fsck.k9.cache
|
||||
package app.k9mail.core.common.cache
|
||||
|
||||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.Instant
|
||||
|
||||
internal class ExpiringCache<KEY : Any, VALUE : Any>(
|
||||
class ExpiringCache<KEY : Any, VALUE : Any>(
|
||||
private val clock: Clock,
|
||||
private val delegateCache: Cache<KEY, VALUE> = InMemoryCache(),
|
||||
private var lastClearTime: Instant = clock.now(),
|
|
@ -1,6 +1,6 @@
|
|||
package com.fsck.k9.cache
|
||||
package app.k9mail.core.common.cache
|
||||
|
||||
internal class InMemoryCache<KEY : Any, VALUE : Any>(
|
||||
class InMemoryCache<KEY : Any, VALUE : Any>(
|
||||
private val cache: MutableMap<KEY, VALUE> = mutableMapOf(),
|
||||
) : Cache<KEY, VALUE> {
|
||||
override fun get(key: KEY): VALUE? {
|
|
@ -1,6 +1,6 @@
|
|||
package com.fsck.k9.cache
|
||||
package app.k9mail.core.common.cache
|
||||
|
||||
internal class SynchronizedCache<KEY : Any, VALUE : Any>(
|
||||
class SynchronizedCache<KEY : Any, VALUE : Any>(
|
||||
private val delegateCache: Cache<KEY, VALUE>,
|
||||
) : Cache<KEY, VALUE> {
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
package com.fsck.k9.cache
|
||||
package app.k9mail.core.common.cache
|
||||
|
||||
import app.k9mail.core.testing.TestClock
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isFalse
|
||||
import assertk.assertions.isNull
|
||||
import assertk.assertions.isTrue
|
||||
import kotlin.test.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package com.fsck.k9.cache
|
||||
package app.k9mail.core.common.cache
|
||||
|
||||
import app.k9mail.core.testing.TestClock
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isFalse
|
||||
import assertk.assertions.isNull
|
||||
import kotlin.test.Test
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
Loading…
Reference in a new issue