SolidJSS
SolidJS2y ago
13 replies
sabercoy

Can cache be manually set?

Say I have a export const getList = cache(...) and I access the list using createAsync in multiple places in the app
If a user chooses to delete the entire list in some section of the app and the request succeeds, the expected result for the list is now to be empty

To my understanding with the current model, the way to update the list to be empty would be to revalidate it, probably in an action, which would trigger another call to the server to get the new list (which is empty)

but say I want to not go to the server to get the obvious empty-list result. Is there a way I can manually set the list to empty?

I had thought I could use cache.set() to do this, but upon using it nothing seems to happen (at least reactively)

I know it is frowned upon to want to manually mutate state in the UI and not re-ask the server, but I can think of a few scenarios where this is harmless and beneficial.

basically, I am wondering if there is an equivalent mutate() function from createResource for createAsync
Was this page helpful?