Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'maxAge' of undefined #36

Closed
leon opened this issue Sep 2, 2013 · 6 comments
Closed

Cannot read property 'maxAge' of undefined #36

leon opened this issue Sep 2, 2013 · 6 comments
Assignees
Milestone

Comments

@leon
Copy link

leon commented Sep 2, 2013

Somehow maxAge isn't set.

The offending line is:

maxAge = data[key].maxAge || config.maxAge;

they key is set, but data is an empty object.

Maybe we need to put in a null check for maxAge?

@jmdobry
Copy link
Owner

jmdobry commented Sep 2, 2013

I see the missing null check on that line, but I'd like to reproduce the problem and see if the root cause isn't elsewhere. Can you show an example of how to reproduce it?

@ghost ghost assigned jmdobry Sep 2, 2013
@jmdobry
Copy link
Owner

jmdobry commented Sep 3, 2013

The only way this bug can occur is if lruHash and data get out of sync. Looking at the code, it seems this is currently possible if you attempt to add an item to a cache in an invalid way. I should have this loophole closed now.

jmdobry added a commit that referenced this issue Sep 3, 2013
@jmdobry jmdobry closed this as completed Sep 3, 2013
@leon
Copy link
Author

leon commented Sep 3, 2013

if it helps, I have been clearing out entries from localstorage using chromes developer tools. maybe that makes things go haywire. though i have allways deleted both the data and keys entry.

@jmdobry
Copy link
Owner

jmdobry commented Sep 3, 2013

That could very well have been the problem. Angular-cache namespaces all of the entries it puts into localStorage so it doesn't stomp on whatever other things might be using localStorage.

Also, I don't serialize the entirety of angular-cache's internal state to localStorage, only the the key-value pairs. When angular-cache loads it rebuilds its internal state from the key-value pairs. If the key-value pairs are removed from localStorage by some other party while angular-cache is still running in memory (there hasn't been a page refresh) then that would cause angular-cache's internal state to become out of sync with what is in localStorage.

I'll have to look into writing some safe guards to handle this situation. Thanks for bringing it to my attention.

@leon
Copy link
Author

leon commented Sep 3, 2013

I will try out the fix tomorrow and see if the bug has gone away!

Thanks!

@jmdobry
Copy link
Owner

jmdobry commented Sep 3, 2013

I closed one loophole, but see #39 for what may yet be an unsolved issue (and less easy to fix).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants