Handle-with-cache.c

pthread_mutex_lock(&cache_lock); // Double-check: another thread might have inserted it while we were loading entry = g_hash_table_lookup(handle_cache, &user_id); if (entry) { // Discard our loaded profile and use the cached one free_user_profile(profile); entry->ref_count++; pthread_mutex_unlock(&cache_lock); return entry->profile; }

void release_user_profile_handle(UserProfile *profile) { if (!profile) return; handle-with-cache.c

A common optimization is or using a per-key mutex: handle-with-cache.c