Closed bennekrouf closed 8 years ago
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.
I agree.
Thanks for the review.
I can't merge this PR, I think it needs to be updated with master.
+1 for this. Could you explain how is the behavior when localStorage explodes? Data will not be cached anymore? It will use memory?
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.
was this issue ever resolved?
"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.