Skip to content

Commit f8e668e

Browse files
refactor(news): Change article cache key from String to Int
- Modify the `articleCache` map to use `Int` as the key instead of `String`. - Update the caching logic in `getTopHeadlines` to associate articles by their integer `id`.
1 parent 2c1cd5e commit f8e668e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/src/main/java/com/yogiveloper/yonewsai/modules/home_news/data/repository/NewsRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NewsRepositoryImpl @Inject constructor(
1717
* simple cache
1818
* because limitation from news api
1919
* there is no api to hit detail */
20-
private val articleCache = mutableMapOf<String, Article>()
20+
private val articleCache = mutableMapOf<Int, Article>()
2121

2222
override suspend fun getTopHeadlines(country: String, category: String): List<Article> {
2323
try {
@@ -37,7 +37,7 @@ class NewsRepositoryImpl @Inject constructor(
3737
* add all the new articles to the cache in one go.
3838
* */
3939
articleCache.clear()
40-
articleCache.putAll(domainArticles.associateBy { it.id.toString() })
40+
articleCache.putAll(domainArticles.associateBy { it.id })
4141

4242
return domainArticles
4343
} catch (e: Exception){

0 commit comments

Comments
 (0)