jmdobry/angular-data-localForage — pull request #3 by toadkicker (2014-11-23 00:05:19+00:00)
Title: Feature/cache methods

Added cache methods that angular-cache expects (getItem, setItem, removeItem). Below is my implementation. Feedback welcome! Also I noticed there are unfinished tests and three failing ones before I made these changes. They appear to be due to just not being implemented yet.

I'm doing this in my app:
```
app.run(....
DSCacheFactory('mySoCalledCache', {
maxAge: 900000, // Items added to this cache expire after 15 minutes.
cacheFlushInterval: 6000000, // This cache will clear itself every hour.
deleteOnExpire: 'aggressive', // Items will be deleted from this cache right when they expire.
storageMode: 'localforage',
storageImpl: DSLocalForageAdapter
});
```

And then in my resource using DSHttpAdapter:

```
app
.factory('Session', ['DS', 'API_URLS', 'DSHttpAdapter', 'DSCacheFactory', '$rootScope', 'AUTH_EVENTS', '$q',
function (DS, API_URLS, DSHttpAdapter, DSCacheFactory, $rootScope, AUTH_EVENTS, $q) {
'use strict';

var Session = DS.defineResource({
name: 'Session',
endpoint: API_URLS.session,
cache: true,
login: function (user, cb) {
var deferred = $q.defer();
DSHttpAdapter.create(Session, user, {cache: true}).then(function (response) {
deferred.resolve(response);
var sessionCacheFactory = DSCacheFactory.get('mySoCalledCache');
sessionCacheFactory.$$storage.setItem('user', JSON.stringify(response));
});
return deferred.promise;
}
});
return Session;
}]);
```