News for hackers. Stuff that matters.
Re:Ask HN: What are some cool but obscure data structures yo... by andrewingram on Friday July 22, 2022 @05:08AM (#32190066)
Could you use a WeakMap for this instead?
Re:Ask HN: What are some cool but obscure data structures yo... by skrebbel on Friday July 22, 2022 @06:06AM (#32190360)
If 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.
Re:Ask HN: What are some cool but obscure data structures yo... by andrewingram on Friday July 22, 2022 @11:00AM (#32192619)
Ah 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.