0.4.0 • Published 9 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-backupbower install --save angular-http-backupusage
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
9 years ago
0.3.8
10 years ago
0.3.7
10 years ago
0.3.6
10 years ago
0.3.5
10 years ago
0.3.4
10 years ago
0.3.3
10 years ago
0.3.2
10 years ago
0.3.1
10 years ago
0.3.0
10 years ago
0.2.8
10 years ago
0.2.7
10 years ago
0.2.6
10 years ago
0.2.5
10 years ago
0.2.4
10 years ago
0.2.3
10 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago