diff --git a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/api/LinkedHashMapManager.kt b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/api/LinkedHashMapManager.kt index ca29a61..4e21165 100644 --- a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/api/LinkedHashMapManager.kt +++ b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/api/LinkedHashMapManager.kt @@ -23,7 +23,7 @@ internal interface LinkedHashMapManager, K : Comparable, suspend fun getPersistedItem(id: Id): V? suspend fun getCachedPage(key: K): PagingSource. LoadResult. Data? - suspend fun getPersistedPage(key: K): PagingSource. LoadResult. Data? + suspend fun getPersistedPage(params: PagingSource.LoadParams): PagingSource. LoadResult. Data? suspend fun saveItem(item: V) : PersistenceResult suspend fun getItemsInOrder(): List diff --git a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/impl/RealLinkedHashMapManager.kt b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/impl/RealLinkedHashMapManager.kt index 5cc8272..35524a4 100644 --- a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/impl/RealLinkedHashMapManager.kt +++ b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pager/impl/RealLinkedHashMapManager.kt @@ -107,8 +107,25 @@ internal class RealLinkedHashMapManager, K : Comparable, return pageMemoryCache[key] } - override suspend fun getPersistedPage(key: K): PagingSource.LoadResult.Data? { - TODO("Not yet implemented") + override suspend fun getPersistedPage(params: PagingSource.LoadParams): PagingSource.LoadResult.Data? { + 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 { diff --git a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pagingScope/impl/PagingScopeBuilder.kt b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pagingScope/impl/PagingScopeBuilder.kt index 18d1d71..b27b1b2 100644 --- a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pagingScope/impl/PagingScopeBuilder.kt +++ b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/pagingScope/impl/PagingScopeBuilder.kt @@ -103,9 +103,10 @@ class PagingScopeBuilder, K : Comparable, V : Identifiabl override fun setErrorHandlingStrategy(strategy: ErrorHandlingStrategy) = apply { errorHandlingStrategy = strategy } - override fun setPlaceholderFactory(placeholderFactory: PlaceholderFactory): PagingScope.Builder { - TODO("Not yet implemented") - } + override fun setPlaceholderFactory(placeholderFactory: PlaceholderFactory): PagingScope.Builder = + apply { + this.placeholderFactory = placeholderFactory + } override fun setItemMemoryCache(cache: MutableMap) = apply { itemMemoryCache = cache } override fun setPageMemoryCache(cache: MutableMap>) = diff --git a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/store/impl/ConcurrentPageStore.kt b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/store/impl/ConcurrentPageStore.kt index 6590139..11a937e 100644 --- a/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/store/impl/ConcurrentPageStore.kt +++ b/paging-runtime/src/commonMain/kotlin/org/mobilenativefoundation/storex/paging/runtime/internal/store/impl/ConcurrentPageStore.kt @@ -82,7 +82,7 @@ internal class ConcurrentPageStore, K : Comparable, 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")