From 6cfcbdcedec95ef69568884218aa4e1c5d1f58fd Mon Sep 17 00:00:00 2001 From: Brian Giori Date: Fri, 16 Aug 2024 13:58:50 -0700 Subject: [PATCH] fix: add isLoaded and lazy load --- sdk/src/main/java/com/amplitude/experiment/storage/Cache.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/src/main/java/com/amplitude/experiment/storage/Cache.kt b/sdk/src/main/java/com/amplitude/experiment/storage/Cache.kt index f89d9e0..bfd33c6 100644 --- a/sdk/src/main/java/com/amplitude/experiment/storage/Cache.kt +++ b/sdk/src/main/java/com/amplitude/experiment/storage/Cache.kt @@ -16,12 +16,15 @@ internal class LoadStoreCache( private val onLoad: (() -> Unit)? = null, ) { private val cache: MutableMap = mutableMapOf() + private var isLoaded = false fun get(key: String): V? { + if (!isLoaded) load() return cache[key] } fun getAll(): Map { + if (!isLoaded) load() return HashMap(cache) } @@ -62,6 +65,7 @@ internal class LoadStoreCache( clear() putAll(values) onLoad?.invoke() + isLoaded = true } fun store(values: MutableMap = cache) {