-
Notifications
You must be signed in to change notification settings - Fork 77
Cant cache into local storage. #244
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
Comments
Angular-data doesn't use the cache factory for storing data in localStorage, rather you need to use DSLocalStorageAdapter. angular.module('myApp', ['angular-data.DS']).config(function (DSProvider) {
// use the local storage adapter by default
DSProvider.defaults.defaultAdapter = 'DSLocalStorageAdapter';
}).run(function (DS) {
// or a single resource will use it by default
DS.defineResource({
name: 'user',
defaultAdapter: 'DSLocalStorageAdapter'
});
// or just use it for a single call
DS.find('user', 1, { adapter: 'DSLocalStorageAdapter' })
}); See also: |
ok so is there no way for all http requests I make to be cached to local storage automatically by angular-cache? |
There is: angular.module('myApp', ['angular-data.DSCacheFactory']).run(function ($http) {
$http.defaults.cache = DSCacheFactory('myCache', {
storageMode: 'localStorage'
});
}); |
perfect thankyou very much! |
Hi Jason, sorry for the duplicate post. Although I think I am trying to do something slightly different. I am trying to have my app working and usable offline. So I would inject an object into the angular-data datastore. I would then update that object as and when I choose. (all the time the object, and others like it are syncing with localStorage) then when I am online or attempt a async method, I post that object to the server and update my angular data store with the result of that store. Essentially, the client holds the most current data, this data is always synced with localstorage with all synchronous methods. When we do an async method we update the server and client with newly created IDs and potentially other data attributes. |
The only way the data store can interact with localStorage is through DSLocalStorageAdapter. Right now there are no auto-sync features. As far as angular-data is concerned, localStorage is a persistence layer, and the data store can only interact with persistence layers through adapters. Synchronous methods operate on the in-memory data store only. Only the async methods work through the adapters. |
Hi Jason, Thank you for your help with angular data. Again love the work you have All the best and maybe talk soon, On 1 December 2014 at 16:26, Jason Dobry [email protected] wrote:
|
Hi I'm having trouble configuring my resources to cache into local storage.
I've tried defining the following in app config:
DSCacheFactoryProvider.setCacheDefaults({
storageMode: 'localStorage'
});
I've also tried passing the 'storageMethod' option when defining a resource as follows:
DS.defineResource({
name: 'someResource',
idAttribute: 'id',
storageMode: 'localStorage',
endpoint: '/fixtures',
});
all to no avail, I've read the documentation end to end and have found little information on the subject, I've also read the source for angular-data and could only find one reference to storage mode on
line 5640: storageMode: 'memory'... please could you advise on the best solution to this problem? I was thinking of using a third party API to handle local storage, but would much prefer to use angular-data exclusively.
thanks for the great tool by the way!
Dom
The text was updated successfully, but these errors were encountered: