function cacheFunction<F extends (...args: any[]) => any>(fn: F, cacheTime = 60): (...args: Parameters<F>) => ReturnType<F> {
const cache: Map<string, { value: ReturnType<F>, timestamp: number }> = new Map();
return function(...args: Parameters<F>) {
const key = args.toString();
const cached = cache.get(key);
if (cached && Date.now() - cached.timestamp < cacheTime * 1000) {
return cached.value;
}
const result = fn.apply(this, args);
cache.set(key, { value: result, timestamp: Date.now() });
return result;
};
}