Cache optimization#34868
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: 03c3257 The changes in this PR will be included in the next version bump. This PR includes changesets to release 35 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| @@ -0,0 +1,30 @@ | |||
| import { UsersRaw } from '../../../../packages/models/src/models/Users.js'; | |||
There was a problem hiding this comment.
what happens if one instance deletes an user?
There was a problem hiding this comment.
If a user deletes their account but the cache is not cleared, the system might still use old cache data, leading to "user not found" errors when a new account is created. To solve this, it's good to have a command to clear the cache when this error occurs, but an automated system to refresh the cache during account deletion or after some time would be more efficient and user-friendly.
There was a problem hiding this comment.
but what if one instance reads the cache while the 'clear command' is being ran?
NOTE: clearing an object in JS is not an atomic operation
There was a problem hiding this comment.
I don't think we should implement an ACID compliant cache just for this, lets defer to the database to ensure correctness.
feat: Add userCache.ts for cache optimization
This Pull Request adds a new userCache.ts file to make the application faster and more efficient. It uses a simple Map to store user data in memory, so the database is not called every time. This reduces the load on the database and makes the application respond quicker. The cache is also updated when needed to keep the data correct and up-to-date. This change helps the application handle more users without slowing down.
Changes:
userCache.tsfile to implement a Map-based caching mechanism.Tests:
userCache.tsfunctionality.Notes:
UsersRawfor potential optimization.