Async cache clearing
A big part of working with asynchronous data is being able to control the cache.
There's even a famous quote for it:
"There are only two hard things in Computer Science: cache invalidation and naming things."
-Phil Karlton
To try and make at least one of those things a bit easier for you, Pullstate provides a few different ways of dealing with cache invalidation with your async actions.
Direct cache invalidation
There are three "direct" ways to invalidate the cache for an action:
Clear the cache for specific arguments (fingerprint)
GetUserAction.clearCache({ userId });
Clear the cache completely for an action (all combinations of arguments)
GetUserAction.clearAllCache();
Clear all unwatched cache for an action
GetUserAction.clearAllUnwatchedCache();
Conditional cache invalidation
There is also a way to check and clear the cache automatically, using something called a cacheBreakHook
- which runs when an action is called which already has a cached result, and decides whether the current cached result is still worthy. Check out the async hooks flow diagram to better understand how this hook fits in.
Cache Break Hook
cacheBreakHook: ({ result, args, timeCached }) => true | false