File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ export const GET_HTML_SKELETON_CACHE_TTL_SECS = 5 * 60; // 5 minutes
7676export const GET_HTML_SKELETON_CACHE_MAX_SIZE = 200 ;
7777export const MCP_SERVER_CACHE_MAX_SIZE = 500 ;
7878export const MCP_SERVER_CACHE_TTL_SECS = 30 * 60 ; // 30 minutes
79+ export const USER_CACHE_MAX_SIZE = 200 ;
80+ export const USER_CACHE_TTL_SECS = 60 * 60 ; // 1 hour
7981
8082export const ACTOR_PRICING_MODEL = {
8183 /** Rental Actors */
Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ import { createHash } from 'node:crypto';
33import type { User } from 'apify-client' ;
44
55import type { ApifyClient } from '../apify-client.js' ;
6+ import { USER_CACHE_MAX_SIZE , USER_CACHE_TTL_SECS } from '../const.js' ;
7+ import { TTLLRUCache } from './ttl-lru.js' ;
68
7- // Type for cached user info - stores the raw User object from API
8- const userCache = new Map < string , User > ( ) ;
9+ // LRU cache with TTL for user info - stores the raw User object from API
10+ const userCache = new TTLLRUCache < User > ( USER_CACHE_MAX_SIZE , USER_CACHE_TTL_SECS ) ;
911
1012/**
1113 * Gets user info from token, using cache to avoid repeated API calls
@@ -20,8 +22,9 @@ export async function getUserIdFromToken(
2022 const tokenHash = createHash ( 'sha256' ) . update ( token ) . digest ( 'hex' ) ;
2123
2224 // Check cache first
23- if ( userCache . has ( tokenHash ) ) {
24- return userCache . get ( tokenHash ) ! ;
25+ const cachedUser = userCache . get ( tokenHash ) ;
26+ if ( cachedUser ) {
27+ return cachedUser ;
2528 }
2629
2730 // Fetch from API
You can’t perform that action at this time.
0 commit comments