Skip to content

Instantly share code, notes, and snippets.

@TwanoO67
Created September 28, 2016 12:04
Show Gist options
  • Save TwanoO67/aa083a8d1e0e590602c5a5103ececff0 to your computer and use it in GitHub Desktop.
Save TwanoO67/aa083a8d1e0e590602c5a5103ececff0 to your computer and use it in GitHub Desktop.
cache with rs
getFiles(idinfosys, idcategorie){
//when this http request is cached and not old more than 3sec
if(Date.now() > this.cachedData[idcategorie].time+3){
let rs = new ReplaySubject<any>(1);
rs.next(this.cachedData[idcategorie].data);
return rs;
}
// https request isn't cached
return this.http.get(this.SERVER_URL+'dms/list/categories?idinfosys='+idinfosys+'&idcategorie='+idcategorie+'&alf_ticket='+this.TICKET).map((data : Response) => {
// cache this http request
this.cachedData[idcategorie] = {data: data.json(), time: Date.now()}
return data.json()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment