Skip to content

Commit

Permalink
Getting there
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-ramotar committed Jul 7, 2024
1 parent c5561b3 commit 249cec7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal interface LinkedHashMapManager<Id : Identifier<Id>, K : Comparable<K>,
suspend fun getPersistedItem(id: Id): V?

suspend fun getCachedPage(key: K): PagingSource. LoadResult. Data<Id, K, V>?
suspend fun getPersistedPage(key: K): PagingSource. LoadResult. Data<Id, K, V>?
suspend fun getPersistedPage(params: PagingSource.LoadParams<K>): PagingSource. LoadResult. Data<Id, K, V>?

suspend fun saveItem(item: V) : PersistenceResult<Unit>
suspend fun getItemsInOrder(): List<V?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,25 @@ internal class RealLinkedHashMapManager<Id : Identifier<Id>, K : Comparable<K>,
return pageMemoryCache[key]
}

override suspend fun getPersistedPage(key: K): PagingSource.LoadResult.Data<Id, K, V>? {
TODO("Not yet implemented")
override suspend fun getPersistedPage(params: PagingSource.LoadParams<K>): PagingSource.LoadResult.Data<Id, K, V>? {
val result = persistence?.pages?.getPage(params) ?: return null

return when (result) {
is PersistenceResult.Success -> result.data?.also { page ->
// If found in persistent storage, update the memory cache
pageMemoryCache[params.key] = page
}

is PersistenceResult.Error -> {
logger.debug("Error retrieving page: ${result.message}")
null
}

PersistenceResult.Skipped -> {
// Do nothing
null
}
}
}

override suspend fun getItemsInOrder(): List<V?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ class PagingScopeBuilder<Id : Identifier<Id>, K : Comparable<K>, V : Identifiabl
override fun setErrorHandlingStrategy(strategy: ErrorHandlingStrategy) =
apply { errorHandlingStrategy = strategy }

override fun setPlaceholderFactory(placeholderFactory: PlaceholderFactory<Id, K, V>): PagingScope.Builder<Id, K, V> {
TODO("Not yet implemented")
}
override fun setPlaceholderFactory(placeholderFactory: PlaceholderFactory<Id, K, V>): PagingScope.Builder<Id, K, V> =
apply {
this.placeholderFactory = placeholderFactory
}

override fun setItemMemoryCache(cache: MutableMap<Id, V>) = apply { itemMemoryCache = cache }
override fun setPageMemoryCache(cache: MutableMap<K, PagingSource.LoadResult.Data<Id, K, V>>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class ConcurrentPageStore<Id : Identifier<Id>, K : Comparable<K>, V : I

// Attempt to load from persistent storage
logger.debug("Attempting to load page from persistent storage")
val persistedPage = linkedHashMapManager.getPersistedPage(params.key)
val persistedPage = linkedHashMapManager.getPersistedPage(params)

if (persistedPage != null) {
logger.debug("Found page in persistent storage: $persistedPage")
Expand Down

0 comments on commit 249cec7

Please sign in to comment.