ladda-js / ladda

JavaScript data fetching layer with caching
https://petercrona.gitbooks.io/ladda/content/
MIT License
112 stars 16 forks source link

Let Ladda return the same object references - immutable cache #41

Open LFDM opened 6 years ago

LFDM commented 6 years ago

A current pain point with Ladda IMO is that every cache hit gives you a new reference to a cached object. While this is super-safe and makes it impossible to destroy the cache through mutation, it's also a strange contract - especially given current practices around dealing with immutable objects in e.g. React.

The issue is resolved here. For backwards compatibility there's a global flag called strict which defaults to true. It performs an Object.freeze on cache objects, so that we can still guarantee that our cache is not unlawfully manipulated. However, some past users might have violated this rule in the past - strict: false would keep their code alive at least. In addition the flag can be set to false when you just don't want these safeties - we deep freeze everything. Not sure how freeze performs - probably quite quick - still, adds some overhead.

This was done a while ago already - I think it's time to merge it.

On the branch fix/id-from-args-with-lists I just pushed a seemingly unrelated broken test I discovered earlier. This test would also be fixed by the changes made in this PR.

cc @mlent

LFDM commented 6 years ago

This change might be a good case to bump to the next major version even.

mlent commented 6 years ago

@connor-baer @GuyLivni We were hypothesizing that this could be the source of our 'memory leak' that causes the website cache to grow so huge. Can you guys keep an eye on this and have a look once it's released?

mlent commented 6 years ago

@LFDM Any news on the release 😛