Created
September 28, 2016 12:04
-
-
Save TwanoO67/aa083a8d1e0e590602c5a5103ececff0 to your computer and use it in GitHub Desktop.
cache with rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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