API: Cache user for optimized authentication #207
Labels
difficulty: 2
foss hack
Clustering all the curated issues for Foss Hack 2024
help wanted
Extra attention is needed
priority: medium
scope: api
Everything related to the API
type: enhancement
New feature or request
Description
keyshade uses stateless cookie-based authentication to let users in. In the long run, this will impose a strain on our database since we will have over 100qps. To optimize this, we would like to cache our user data during authentication.
Solution
In auth.guard.ts, if the authentication is successful, we fetch the user details and set it in the current session. We would also like to cache this data. We will be using the key structure
user-<userId>
.auth.guard.ts
:user-<userId>
. If it's null, fetch from the database by email.JSON.stringify()
the data retrieved, and set it in cache asuserId -> userObject(stringified)
Additional context
Relevant files can be found in
auth
anduser
module.The text was updated successfully, but these errors were encountered: