MobileNativeFoundation / MobileNativeFoundation/Store
Feature Request: Define custom actions when cache become invalidated
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 3.4k
- Forks
- 217
- Avg merge
- 18m
- Merged PRs (30d)
- 4
Description
Is it possible to execute some custom actions when memory cache become invalidated?
I am trying to integrate Jetpack Paging with Store.
The DataSource required us to call invalidate when we want to stop paging.
Currently, I am using a map to cache the latest result and invalidate old one from the fetcher:
val dataSourceMap = mutableMap<Key, WeakReference<PagedList>>()
val store = StoreBuilder.fromNonFlow { key: Key ->
val pagedList = createPagedList(key)
dataSourceMap[key]?.get()?.dataSource?.invalidate()
dataSourceMap[key] = WeakReferene(pagedList)
pagedList
}.build()
Maybe it will be convenient if StoreBuilder can provide a onCacheInvalidated method:
val store = StoreBuilder.fromNonFlow { key: Key ->
createPagedList(key)
}.onCacheInvalidate { pagedList ->
pagedList.dataSource.invalidate()
}.build()
Edit: Use WeakReference
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing StoreBuilder and the cache invalidation path to understand when cached values are discarded. Define the callback's timing and value semantics, then add the requested invalidation behavior and coverage in the existing cache tests; done means callers can trigger the Jetpack Paging DataSource invalidation when its cached value is replaced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100