Hard
You're implementing a caching system for expensive calculations in a web application. The cache should automatically clear old entries to prevent memory leaks. What's missing in this implementation?
1class ComputeCache {2 constructor(maxSize = 100) {3 this.maxSize = maxSize;4 this.cache = new Map();5 }67 generateKey(...args) {8 return JSON.stringify(args);9 }1011 compute(fn, ...args) {12 // Missing implementation13 _______________14 }1516 set(key, value) {17 if (this.cache.size >= this.maxSize) {18 const oldestKey = this.cache.keys().next().value;19 this.cache.delete(oldestKey);20 }21 this.cache.set(key, {22 value,23 timestamp: Date.now()24 });25 return value;26 }2728 clear() {29 this.cache.clear();30 }31}3233// Usage:34const cache = new ComputeCache(2);35const expensiveOp = (a, b) => {36 console.log('Computing...');37 return new Promise(resolve =>38 setTimeout(() => resolve(a + b), 1000)39 );40};