Skip to main content
Glama

actors-mcp-server

Official
by apify
userid-cache.ts1.08 kB
import { createHash } from 'node:crypto'; import type { ApifyClient } from '../apify-client.js'; import { USER_CACHE_MAX_SIZE, USER_CACHE_TTL_SECS } from '../const.js'; import { TTLLRUCache } from './ttl-lru.js'; // LRU cache with TTL for user info - stores the raw User object from API const userIdCache = new TTLLRUCache<string>(USER_CACHE_MAX_SIZE, USER_CACHE_TTL_SECS); /** * Gets user ID from token, using cache to avoid repeated API calls * Token is hashed before caching to avoid storing raw tokens * Returns userId or null if not found */ export async function getUserIdFromTokenCached( token: string, apifyClient: ApifyClient, ): Promise<string | null> { const tokenHash = createHash('sha256').update(token).digest('hex'); const cachedId = userIdCache.get(tokenHash); if (cachedId) return cachedId; try { const user = await apifyClient.user('me').get(); if (!user || !user.id) { return null; } userIdCache.set(tokenHash, user.id); return user.id; } catch { return null; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apify/actors-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server