Skip to content

Instantly share code, notes, and snippets.

@feliperohdee
Created March 15, 2016 16:43
Show Gist options
  • Save feliperohdee/9fd7cb44d24b1adf146c to your computer and use it in GitHub Desktop.
Save feliperohdee/9fd7cb44d24b1adf146c to your computer and use it in GitHub Desktop.
Observable cache
let cache = (source: Observable<any>) => {
let replay: ReplaySubject<any>;
return source
.multicast(() => {
if (!replay) {
replay = new ReplaySubject(2);
setTimeout(() => replay = null, 2500);
}
return replay;
})
.refCount();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment