0.4.0 • Published 7 years ago
angular-http-backup v0.4.0
angular-http-backup
##Replay cached data when network/service fails
####Each successful request is cached in localStorage with url as the key. When the network/service fails, a cached response will be served up
Getting Started
npm install --save angular-http-backup
bower install --save angular-http-backup
usage
angular
.module( 'your.module', [ 'httpbackup' ] )
.config( $httpProvider, httpBackupCacheProvider ) {
$httpProvider.interceptors.push( 'httpBackupInterceptor' );
// by default all urls are cached,
// this allows regex to limit what gets cached
httpBackupCacheProvider.setCachingRules( [
new RegExp( "^api\/v1" ), //cache request urls starting with "api/v1"
new RegExp("^(?!.*[.]html$).*$") //ignore request urls ending with ".html"
] );
}
Resetting cache
// inject httpBackupCache
function controller(httpBackupCache){
//reset all keys
httpBackupCache.clear();
// remove individual key
httpBackupCache.removeItem('GET:api/v1/auth/login');
httpBackupCache.removeItem('POST:api/v1/auth/status');
httpBackupCache.removeItem('PUT:api/v1/auth/ping');
}
Events
// event $emitted on $rootScope when a response is cached
$rootScope.$on( 'HttpBackup_cached', function( event, data ) {
console.log(data.url); // request url
console.log(data.response); // cached response
}
// event $emitted on $rootScope when a cached response is used
$rootScope.$on( 'HttpBackup_activated', function( event, data ) {
console.log(data.url); // request url
console.log(data.response); // cached response
}
0.4.0
7 years ago
0.3.8
8 years ago
0.3.7
8 years ago
0.3.6
8 years ago
0.3.5
8 years ago
0.3.4
8 years ago
0.3.3
8 years ago
0.3.2
8 years ago
0.3.1
8 years ago
0.3.0
8 years ago
0.2.8
8 years ago
0.2.7
8 years ago
0.2.6
8 years ago
0.2.5
8 years ago
0.2.4
8 years ago
0.2.3
8 years ago
0.2.2
8 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.2
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago