vshymanskyy/muon

Should LRU cache apply to arbitrary objects, not only strings?

vshymanskyy opened this issue · 2 comments

Should LRU cache apply to arbitrary objects, not only strings?

One question that immediately comes to mind: during deserialization, should cached objects be (deep)cloned, or should it assign multiple references to the same object?

I'm guessing cloning has the most consistent and predictable behavior when crossing language boundaries (not all languages have references), and it would also match how multiple references to the same object get turned into separate objects after a roundtrip through JSON.stringify/JSON.parse:

    const t = {foo: "bar"}, t2 = {a: t, b: t};
    console.log(JSON.stringify(t2));
   //  ==> {"a":{"foo":"bar"},"b":{"foo":"bar"}}

(sorry if I come across as asking the obvious, but it pays to be explicit and pedantic with these things, right?)

After thinking more about it, I don't think it's worth mixing string references and generic references.
If it becomes absolutely necessary in future, a new tag can be added for that specific purpose