Check the website: https://jmdobry.github.io/angular-cache/#using-angular-cache-with-http
Install:
npm install --save angular-cache
getServiceDetail( serviceId = "mock" ) { if(!this.CacheFactory.get(`${this.prefix}.${serviceId}`)){ this.$http.defaults.cache = this.CacheFactory(`${this.prefix}.${serviceId}`, { maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour deleteOnExpire: 'aggressive' // Items will be deleted from this cache when they expire }); } return this.$http.get( `${this.CONFIG.BACKEND_API_URL}/services/${serviceId}/details`, { cache: this.CacheFactory.get(`${this.prefix}.${serviceId}`) } ) .then( ( res ) => { return res.data.serviceDetail; }, ( err ) => { this.$log.debug( `ServiceDetails --> getServiceDetail err: Cannnot get detail data: ${JSON.stringify( err, null, 3 )}` ); throw err; } ); } }