fix: default timeout on user caches of 15 min (#2530)
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled

This commit is contained in:
Daniel Salazar
2026-02-23 14:21:24 -08:00
committed by GitHub
parent e60f55f20e
commit eda9f117c7
2 changed files with 8 additions and 4 deletions
+2 -2
View File
@@ -290,7 +290,7 @@ export async function get_user (options) {
* @param {User} userID - the user entry to invalidate
*/
export const invalidate_cached_user = async (user) => {
UserRedisCacheSpace.invalidateUser(user);
await UserRedisCacheSpace.invalidateUser(user);
};
/**
@@ -298,7 +298,7 @@ export const invalidate_cached_user = async (user) => {
* @param {number} id - the id of the user to invalidate
*/
export const invalidate_cached_user_by_id = async (id) => {
UserRedisCacheSpace.invalidateById(id);
await UserRedisCacheSpace.invalidateById(id);
};
export async function refresh_associations_cache () {
@@ -21,6 +21,7 @@ import { deleteRedisKeys } from '../clients/redis/deleteRedisKeys.js';
const userKeyPrefix = 'users';
const defaultUserIdProperties = ['username', 'uuid', 'email', 'id', 'referral_code'];
const DEFAULT_USER_CACHE_TTL_SECONDS = 15 * 60;
const safeParseJson = (value, fallback = null) => {
if ( value === null || value === undefined ) return fallback;
@@ -51,7 +52,10 @@ const UserRedisCacheSpace = {
},
getByProperty: async (prop, value) => safeParseJson(await redisClient.get(userCacheKey(prop, value))),
getById: async (id) => UserRedisCacheSpace.getByProperty('id', id),
setUser: async (user, { props = defaultUserIdProperties, ttlSeconds } = {}) => {
setUser: async (
user,
{ props = defaultUserIdProperties, ttlSeconds = DEFAULT_USER_CACHE_TTL_SECONDS } = {},
) => {
if ( ! user ) return;
const serialized = JSON.stringify(user);
const writes = [];
@@ -72,7 +76,7 @@ const UserRedisCacheSpace = {
invalidateById: async (id, props = defaultUserIdProperties) => {
const user = await UserRedisCacheSpace.getById(id);
if ( ! user ) return;
UserRedisCacheSpace.invalidateUser(user, props);
await UserRedisCacheSpace.invalidateUser(user, props);
},
};