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

fix(Local Storage) Catch and manage exception when local storage size is reached #139

Closed
wants to merge 10 commits into from

Conversation

bennekrouf
Copy link

"capacity" does not prevent from having a maximum size reached exception with the local storage.

Here, the idea is to catch this exception (around setItem), compute the size of the item that is provoking the exception. Then, removing from the cache oldest item until there are enough space for adding this new item.

@jmdobry
Copy link
Owner

jmdobry commented Nov 4, 2014

I will review this.

I also wanted to point out that this may not work in all situations, as localStorage my have been filled up by something other than angular-cache. In addition, if you've created multiple cache instances, this solution can only prevent a single instance from filling up localStorage. During the attempt to free up space, only that instance will be removing old items. If other cache instance have put a bunch of stuff in localStorage, their items will remain.

@bennekrouf
Copy link
Author

I agree.

Thanks for the review.

@jmdobry
Copy link
Owner

jmdobry commented Feb 2, 2015

I can't merge this PR, I think it needs to be updated with master.

@marlonpp
Copy link

+1 for this.
Could you explain how is the behavior when localStorage explodes?
Data will not be cached anymore? It will use memory?

@bennekrouf
Copy link
Author

bennekrouf commented May 15, 2015

With this PR, if the max LS size is reached during a put, I remove 30% of the cache and do the put.

We can imagine relying on memory in this case, but I think it would confuse the user by having some data in memory (flushable by F5) and others in LS... only based on technical considerations.

benek and others added 2 commits May 15, 2015 11:05
Conflicts:
	dist/angular-cache.js
	src/DSCache/put.js
@bdkent
Copy link

bdkent commented Aug 24, 2016

was this issue ever resolved?

@jmdobry
Copy link
Owner

jmdobry commented Aug 25, 2016

@bdkent #180 (comment)

@bennekrouf bennekrouf closed this Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants