Ability to skip reading the cache in unstable_cache
#64859
michaelschufi
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
Situation
How to check and cache?
Before saving
Before saving the new data, we have the following data in the cache/db:
During the check
We can do the check we need to do in a DB transaction, and act depending on the result.
Data in cache/db during the transaction:
Situation #1 💡: We want to skip reading the cache for the db query and the calculation. (goal #1)
Case 1: Check result: "NOT OK"
In case the data should not be saved (since the check is returned false), the db data is reverted and the cache remains untouched.
Situation #2 💡: We do not want to write into the cache.
Case 2: Check result: "OK"
The data should be saved to the db and the cache updated accordingly.
Situation #3 💡: We want to write to the cache depending on the result.
Since at the time of the db query, we do not know the calculation result, we cannot cache that (non-goal #1), but the calculation should be cachable right away (goal #2).
Proposal
Proposal
Allow specifying the behaviour of
unstable_cache
.Option
skipRead
Add an option called
skipRead
which allows skipping the reading from the cache. It should re-calculate the result to be cached.Simulating a Cache-MISS so to speak.
Notes
Some thoughts on workarounds (and why they are not ideal).
Not use
unstable_cache
for the calculation inside the transaction-> We cannot cache the result to the same key and need to re-run the calculation after commiting the DB transaction.
**Using
revalidateTag
**Needs re-running of either the original or the new calculation.
Do something custom
We don't have the other featuers of
unstable_cache
.Beta Was this translation helpful? Give feedback.
All reactions