Skip to content

Commit 5449058

Browse files
committed
Set diskLruCache to null after deleting all cache
1 parent a63dc19 commit 5449058

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

component-tts/src/main/java/com/github/deweyreed/timer/component/tts/TtsBakeryDiskCache.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import java.io.IOException
99
import java.security.MessageDigest
1010

1111
internal object TtsBakeryDiskCache {
12-
private lateinit var diskLruCache: DiskLruCache
12+
private var diskLruCache: DiskLruCache? = null
1313

1414
private fun getDiskLruCache(context: Context): DiskLruCache {
15-
if (!::diskLruCache.isInitialized) {
15+
if (diskLruCache == null) {
1616
diskLruCache = DiskLruCache.open(
1717
File(context.cacheDir, "tts-bakery"),
1818
1,
1919
1,
2020
100 * 1024 * 1024
2121
)
2222
}
23-
return diskLruCache
23+
return checkNotNull(diskLruCache)
2424
}
2525

2626
fun get(context: Context, text: String): File? {
@@ -84,6 +84,7 @@ internal object TtsBakeryDiskCache {
8484
fun deleteAll(context: Context) {
8585
try {
8686
getDiskLruCache(context).delete()
87+
diskLruCache = null
8788
} catch (e: IOException) {
8889
Timber.e(e)
8990
}

0 commit comments

Comments
 (0)