3 ms·
Could you use a WeakMap for this instead?
by andrewingram 4y ago
Could you use a WeakMap for this instead?
- skrebbel 4y agoIf the key is a type that you expect to be GC'ed, yes, totally. If the key is a simple value type eg a string then it behaves the same as a regular Map or an object.
- andrewingram 4y agoAh yeah, good point. I've mostly used this overall pattern with something like Dataloader, where you throw away the entire cache on every request, so the GC problem doesn't crop up.