Remove List from Cache with ApolloStore

Whats the best way to remove a list from ApolloStore on Kotlin?

This is the cached list:

"newTab({"cursor":0})" : [
CacheKey(Post:217)
CacheKey(Post:216)
CacheKey(Post:215)
CacheKey(Post:214)
CacheKey(Post:213)
CacheKey(Post:212)
CacheKey(Post:211)
CacheKey(Post:210)
CacheKey(Post:209)]

is there a better way then calling

apolloStore.remove(List)

Can I maybe search for “newTab” list in the cache and just simply remove all the items that are in this list?

Because I want a CacheFirst behaviour most of the time except when I do the Swip to Refresh pull.

Doing it like this didn’t work:

        var fetchPolicy = FetchPolicy.CacheFirst
        if(isRefresh){ 
            fetchPolicy = FetchPolicy.NetworkOnly
        }

Hi :wave:

That’s unexpected. I would expect that to work for pull-to-refresh scenarios. Can you elaborate on what’s not working when doing this?

Can I maybe search for “newTab” list in the cache and just simply remove all the items that are in this list?

If you know the CacheKey of your field, you should be able to remove it with apolloStore.remove(cacheKey) but that’s using lower level APIs than just FetchPolicy.NetworkOnly so I would try to make FetchPolicy.NetworkOnly work in the first place

Ah yes, sorry.

    var fetchPolicy = FetchPolicy.CacheFirst
    if(isRefresh){ 
        fetchPolicy = FetchPolicy.NetworkOnly
    }

is indeed working fine.

I messed up something with Jetpack Compose, thats why it didn’t update the list.

1 Like