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

offer option to store data at localstorage #26

Closed
atian25 opened this issue Aug 13, 2013 · 11 comments
Closed

offer option to store data at localstorage #26

atian25 opened this issue Aug 13, 2013 · 11 comments
Assignees
Milestone

Comments

@atian25
Copy link

atian25 commented Aug 13, 2013

No description provided.

@jmdobry
Copy link
Owner

jmdobry commented Aug 13, 2013

What is your use case? How would you expect angular-cache to behave if the browser doesn't support localStorage?

@atian25
Copy link
Author

atian25 commented Aug 14, 2013

I'm writing hybrid app which support localstorage.
I don't think angular-cache must embed localstorage code, but just offer some interface to sync between cache and localstorage, such as:

  1. cache add/remove/clear/timeout event
  2. or offer a setCache() interface

@atian25
Copy link
Author

atian25 commented Aug 14, 2013

my use case is :

  • has many webview , load local html, will load data from server ($http)
  • cache $http data at localstorage so next time user refresh the page or visit a new page at another webview which load the same data url, can share the cache.

@jmdobry
Copy link
Owner

jmdobry commented Aug 14, 2013

Sounds reasonable enough, and local storage isn't actually that much code. How would you expect angular-cache to behave if a user hits your app in a browser that doesn't support local storage?

@atian25
Copy link
Author

atian25 commented Aug 15, 2013

I don't care about that...

because my use case is mobile app, it's well support ( http://caniuse.com/#feat=namevalue-storage).
and it's hybrid app using webview, so doesn't use private browsing mode.
and I don't think fall back to cookie is a good idea, it can only store 4k but slow down the request.

If browser doesn't support, then just using current memory cache or just offer some interface for developers to provide a special cache factory.
and maybe some add/remove/clear/timeout event

@jmdobry
Copy link
Owner

jmdobry commented Aug 15, 2013

Alright, this weekend I should have some time to work on this. If the browser doesn't support localStorage then I'll let the dev provide a localStorage polyfill to angular-cache, or rely on in-memory storage only.

@ghost ghost assigned jmdobry Aug 16, 2013
@jmdobry
Copy link
Owner

jmdobry commented Aug 20, 2013

  • - Modify angular-cache to support using localStorage/sessionStorage behind the scenes
  • - Fully unit-test the modifications
  • - Update the documentation
  • - Update the demo

@jmdobry jmdobry mentioned this issue Aug 20, 2013
4 tasks
jmdobry referenced this issue Aug 21, 2013
Finished localStorage implementation. Now for some tests.

Added some tests to the localStorage feature.

Finished unit tests for localStorage feature.

Updated coverage.
@jmdobry
Copy link
Owner

jmdobry commented Aug 21, 2013

@atian25 I've got the implementation done and the unit tests written. If you'd like, I would appreciate it if you tried out the version of angular-cache in the feature-localStorage branch to see how the localStorage feature works for you. I just need to update the docs and it's done.

Usage:

$angularCacheFactory('myCache', { storageMode: 'localStorage' });

Note It's the developer's responsibility to provide a polyfill for the global localStorage and sessionStorage objects if the browser does not support them.

@atian25
Copy link
Author

atian25 commented Aug 21, 2013

thanks for your work! I will try out it.

another new question: could I use specail storageMode without override gloabal localStorage?

this issue due to a bad news: one of my workmate, he said there's some localstorage compatibility issues with android webview (such as can't share localstorage between webviews, or lost data...)

so if it is true, I'm afraid we had to write a java interface to provide a specail storageMode, then export it to a javascript interface JSBridge.cache.setItem() ( it will provide functions as same as localstorage), but will not override the gloabal localStorage.

@atian25
Copy link
Author

atian25 commented Aug 21, 2013

after a quick code review, could we just set config.storage to my JSBridge.cache ?

@jmdobry
Copy link
Owner

jmdobry commented Aug 21, 2013

I will allow the following:

$angularCacheFactory('newCache', {
  storageMode: 'localStorage',
  localStorage: myLocalStorageImpl // Can be set to your own localStorage. Defaults to window.localStorage
  sessionStorage: mySessionStorageImpl // Can be set to your own sessionStorage. Defaults to window.sessionStorage
});

Your implementations will of course have to implement to same interface as the global localStorage and sessionStorage variables.

I will work on it tomorrow, as it is bedtime here.

@jmdobry jmdobry closed this as completed Aug 21, 2013
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