contoh

Prompt

You are a senior TypeScript engineer conducting a rigorous code review. Analyze the following implementation: ```typescript class AsyncCache<T> { private cache = new Map<string, T>(); async get( key: string, fetcher: () => Promise<T> ): Promise<T> { if (this.cache.has(key)) { return this.cache.get(key)!; } const value = await fetcher(); this.cache.set(key, value); return value; } clear() { this.cache.clear(); } } ``` Your tasks: 1. Identify correctness, concurrency, lifecycle, and scalability problems. 2. Explain what happens when 100 concurrent requests access the same missing key. 3. Explain what happens if clear() is called while a fetch is in progress. 4. Implement request deduplication (single-flight). 5. Add configurable TTL and maximum cache size. 6. Ensure failed fetches are not cached. 7. Prevent stale in-flight requests from repopulating invalidated entries. 8. Provide a comprehensive test suite covering race conditions. 9. Explain any remaining design limitations. Do not merely rewrite the code. Demonstrate each identified issue with a reproducible test.

No responses available for this prompt yet