Undone user cache changes

This commit is contained in:
adrinr 2023-02-01 17:20:48 +00:00
parent 79ee85dab3
commit 11fa2313f1
1 changed files with 4 additions and 10 deletions

View File

@ -49,11 +49,10 @@ export async function getUser(
} }
const client = await redis.getUserClient() const client = await redis.getUserClient()
// try cache // try cache
const cacheKey = getCacheKey(tenantId!, userId) let user = await client.get(userId)
let user = await client.get(cacheKey)
if (!user) { if (!user) {
user = await populateUser(userId, tenantId) user = await populateUser(userId, tenantId)
await client.store(cacheKey, user, EXPIRY_SECONDS) await client.store(userId, user, EXPIRY_SECONDS)
} }
if (user && !user.tenantId && tenantId) { if (user && !user.tenantId && tenantId) {
// make sure the tenant ID is always correct/set // make sure the tenant ID is always correct/set
@ -62,12 +61,7 @@ export async function getUser(
return user return user
} }
export async function invalidateUser(userId: string, tenantId?: string) { export async function invalidateUser(userId: string) {
tenantId = tenantId || getTenantId()
const cacheKey = getCacheKey(tenantId, userId)
const client = await redis.getUserClient() const client = await redis.getUserClient()
await client.delete(cacheKey) await client.delete(userId)
} }
const getCacheKey = (tenantId: string, userId: string) =>
`${tenantId}_${userId}`