Closed GulinSS closed 10 years ago
So I can review this and better understand what was broken, can you create a fiddle that shows the bug?
Okay, I've figured out what the "problem" is. The _verifyIntegrity
method is one-directional–it forces localStorage
to mirror the state of the data that's in memory. Looking at this fiddle (http://jsfiddle.net/4DRAZ/2/), clicking refresh on the second doesn't show the string on the first tab because the get
operation on the second tab overwrites whatever is in localStorage
with what is in memory in the second tab.
I think this is a "problem" when you have the app open in two tabs in the same browser. The verifyIntegrity
functionality was intended to preserve localStorage
, or prevent any other tab from messing with the data–not to synchronize data across tabs. The question is how to reconcile these two different behaviors/use cases.
I think the necessary fix is to modify the behavior of verifyIntegrity
so instances of angular-cache can play nicely across multiple tabs. Right now (and this is how it was originally designed) each instance on each tab is trying to keep localStorage
in sync with its own data and not allow "external" (like a cache in a different tab) to mess with the data.
I propose that verifyIntegrity
be modified to be a two-way synchronization, instead of a one-way. This will fix the issue you raised in #89.
@jmdobry you can do it as you want. :-) I use a bit different approach just because to keep backward compatibility.
I found an sad error in my approach. I will fix it and resend the pull request.
Test it: