Created
April 10, 2025 13:13
-
-
Save nazaslater/d63ccecdb589087cfccdadaf63ba3d8f to your computer and use it in GitHub Desktop.
Página de teste da função memoize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { memoize } from './memoize'; | |
// Função simulando cálculo pesado | |
function slowAdd(a: number, b: number): number { | |
console.log(`Calculando: ${a} + ${b}`); | |
return a + b; | |
} | |
// Criando função memoizada | |
const memoAdd = memoize(slowAdd, { maxSize: 2, ttl: 3000 }); | |
// Execuções | |
console.log("Resultado 1:", memoAdd(2, 3)); // Calcula | |
console.log("Resultado 2:", memoAdd(2, 3)); // Cacheado | |
setTimeout(() => { | |
console.log("Resultado 3 (após 4s):", memoAdd(2, 3)); // TTL expirou, recalcula | |
}, 4000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment