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

Expand documentation to include common use cases (better examples) #31

Closed
jmdobry opened this issue Aug 22, 2013 · 2 comments
Closed

Expand documentation to include common use cases (better examples) #31

jmdobry opened this issue Aug 22, 2013 · 2 comments
Assignees
Milestone

Comments

@jmdobry
Copy link
Owner

jmdobry commented Aug 22, 2013

Show how to use $angularCacheFactory with the $http service, for example.

@CMCDragonkai
Copy link

Can you provide an example how to use polyfills for the localstorage or session storage.

For example store.js is a pretty good polyfill. How to do I wrap the functionality of store.js so I can pass it into the cache factory.

I know you have said it needs setItem... etc, but there's no documentation on what the interface of those methods need to be. Such as parameters and what should return, and most importantly the actual intention of those methods.

@jmdobry
Copy link
Owner Author

jmdobry commented Aug 22, 2013

angular-cache expects to find global localStorage and sessionStorage objects that implement the interface explained by the W3C Recommendation.

As far as the documentation for the interface for setItem, getItem, and removeItem, here it is:

The entire interface looks like this:

interface Storage {
  readonly attribute unsigned long length;
  DOMString? key(unsigned long index);
  getter DOMString getItem(DOMString key);
  setter creator void setItem(DOMString key, DOMString value);
  deleter void removeItem(DOMString key);
  void clear();
};

store.js appears to be a wrapper and polyfill for localStorage, exposing a completely different API to the developer. To use store.js you would need to create a proxy JavaScript Object that wraps the store.js API and exposes the standard W3C recommended API to angular-cache. For example:

var storeJsToStandard {
  getItem: store.get,
  setItem: store.set,
  removeItem: store.remove
};

$angularCacheFactory('myNewCache', {
  storageMode: 'localStorage',
  localStorageImpl: storeJsToStandard
});

EDIT:
There are two ways to do polyfills:

  • Create the global localStorage and sessionStorage objects in browsers that don't provide them
  • Pass the polyfills directly to angular-cache with the localStorageImpl and sessionStorageImpl configuration parameters.

@ghost ghost assigned jmdobry Aug 22, 2013
jmdobry added a commit that referenced this issue Aug 24, 2013
@jmdobry jmdobry mentioned this issue Aug 24, 2013
2 tasks
@jmdobry jmdobry closed this as completed Aug 24, 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