-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds ability to delete a cache entry #7016
Conversation
@@ -185,8 +185,28 @@ export const createCache = ( | |||
return cache(latestCacheKey, () => model.findMany(conditions), rest) | |||
} | |||
|
|||
const deleteCacheKey = async (key: CacheKey) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps an an alias (or rename) deleteCacheKey
to invalidate
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since both libs called the function delete
(and del
) I figured it was best to stay with that nomenclature. I know we talk about "invalidating the cache" but I wonder if that's the proper term to use for what we're doing...invalidation sounds like it's still around, it's just not "valid" any more. Whereas memcached and Redis really seem to delete it from memory and it's no longer available...
* Adds deleteCacheKey() to exported cache functions * Reorg tests * Remove some comments * Update types, simplify Redis return on del() * Fix double not on promise * Add info block about using a hash of columns in the key
* Adds deleteCacheKey() to exported cache functions * Reorg tests * Remove some comments * Update types, simplify Redis return on del() * Fix double not on promise * Add info block about using a hash of columns in the key
….com:redwoodjs/redwood into feat/dc-kc-decoupled-auth-setup-improvements * 'feat/dc-kc-decoupled-auth-setup-improvements' of github.com:redwoodjs/redwood: chore(deps): update dependency nx to v15.3.2 (#7114) chore(deps): update dependency redis to v4.5.1 (#7115) fix: add missing deps to cli helpers (#7117) Adds ability to delete a cache entry (#7016) Label override flags for dbAuth generator (#6440) fix(deps): update dependency systeminformation to v5.16.6 (#7108) feat: Generator rollbacks (#6947) fix(deps): update dependency @types/node to v16.18.8 (#7107) chore(deps): update dependency supertokens-node to v12.1.3 (#7105)
This adds the ability to delete a cache entry by its key. This will allow you to be a little more lax in your cache key names if you know you have circumstances where you bust the cache explicitly so that it can be re-built.
Consider an example where you are caching a post by its
id
. You currently have no way to bust the cache when the post itself changes in some way. But if you can manually delete the cache entry when updating or deleting a post, you are good to go:Of course this assumes that this service is the only place where a post is updated. If not, you either need to make duplicate
deleteCacheKey()
calls, or come up with a key that automatically busts the cache on a post change (like incorporating theupdatedAt
timestamp).The
deleteCacheKey()
function will returntrue
if the key was found and deleted, otherwise it returnsfalse
.Thanks for the suggestion @dthyresson!
Closes #7003