You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the 'memory' backend, getting a value returns a reference to the object in the backend map. Mutating the returned object affects the contents of the map, and therefore all subsequent get calls.
Since this obviously can't happen with memcached, I figure it's a bug.
Obviously a deep copy for every get operation has some performance implications, so I wanted to get your opinion before throwing you a PR. The way I see it there are three options:
Keep the behavior, document it (in bold and underline)
Always deep copy the value before returning it
Add a config parameter to the memory backend to let the user choose whether to copy or not
The text was updated successfully, but these errors were encountered:
We did stringify initially for the memory backend but it led to serious performance issues. So I'd definitely prefer just having a note in the docs. E.g. we use it in some places to store large Buffer instances where copy would be pretty expensive (and undo a lot of the advantages of caching in the first place).
In my experience copy on read is often a suboptimal solution and using immutable data structures (even just Object.freeze) is more efficient. But I wouldn't want to make cached opinionated on how apps handle immutability. That would be my argument against option 3.
When using the 'memory' backend, getting a value returns a reference to the object in the backend map. Mutating the returned object affects the contents of the map, and therefore all subsequent
get
calls.Since this obviously can't happen with memcached, I figure it's a bug.
E.g.:
Obviously a deep copy for every
get
operation has some performance implications, so I wanted to get your opinion before throwing you a PR. The way I see it there are three options:memory
backend to let the user choose whether to copy or notThe text was updated successfully, but these errors were encountered: