Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(network_wallet_services): AND-6800 Create Cache for Coin Network…
…s (#4142)
- Loading branch information
1 parent
50a0a0b
commit ab796b3
Showing
3 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
coincore/src/main/java/com/blockchain/coincore/loader/CoinNetworksStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.blockchain.coincore.loader | ||
|
||
import com.blockchain.api.coinnetworks.data.CoinNetworkDto | ||
import com.blockchain.api.services.AssetDiscoveryApiService | ||
import com.blockchain.store.Fetcher | ||
import com.blockchain.store.Store | ||
import com.blockchain.store.impl.Freshness | ||
import com.blockchain.store.impl.FreshnessMediator | ||
import com.blockchain.store_caches_persistedjsonsqldelight.PersistedJsonSqlDelightStoreBuilder | ||
import com.blockchain.storedatasource.FlushableDataSource | ||
import kotlinx.serialization.builtins.ListSerializer | ||
|
||
class CoinNetworksStore( | ||
private val discoveryService: AssetDiscoveryApiService | ||
) : Store<List<CoinNetworkDto>> by PersistedJsonSqlDelightStoreBuilder() | ||
.build( | ||
storeId = STORE_ID, | ||
fetcher = Fetcher.ofOutcome( | ||
mapper = { | ||
discoveryService.allNetworks() | ||
} | ||
), | ||
dataSerializer = ListSerializer(CoinNetworkDto.serializer()), | ||
mediator = FreshnessMediator(Freshness.DURATION_24_HOURS) | ||
), | ||
FlushableDataSource { | ||
|
||
override fun invalidate() { | ||
markAsStale() | ||
} | ||
|
||
companion object { | ||
private const val STORE_ID = "CoinNetworksStore" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters