Commit 9dac95c2 by Tuukka Kivilahti

removed cache from angular zone detection, so it does not trigger change detection on cleanup

1 parent 610b0988
...@@ -20,6 +20,10 @@ export class AppComponent { ...@@ -20,6 +20,10 @@ export class AppComponent {
}); });
// Enable change detection sometimes to see that it's not overflooded.
// bcause it takes time
//zone.onMicrotaskEmpty.subscribe(() => {console.log(".");}); // <-- Print "." everytime change detection is possibly
} }
......
import {NgModule, ModuleWithProviders} from '@angular/core'; import {NgModule, ModuleWithProviders, NgZone} from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import {HttpModule} from "@angular/http"; import {HttpModule} from "@angular/http";
import {MoyaRestService} from "./services/moya-rest.service"; import {MoyaRestService} from "./services/moya-rest.service";
......
import {Injectable} from "@angular/core"; import {Injectable, NgZone} from "@angular/core";
import {Observable, Subscriber, Subscription} from "rxjs"; import {Observable, Subscriber, Subscription} from "rxjs";
...@@ -45,8 +45,9 @@ export class CacheService { ...@@ -45,8 +45,9 @@ export class CacheService {
// TODO: timed clearup for cache to save memory // TODO: timed clearup for cache to save memory
constructor() { constructor(private zone : NgZone) {
this.cache = new Map<string, CachedItem>(); this.cache = new Map<string, CachedItem>();
this.timerObservable = Observable.timer(30000, 30000); // afther 0.5min, every 0.5min. this.timerObservable = Observable.timer(30000, 30000); // afther 0.5min, every 0.5min.
} }
...@@ -131,7 +132,13 @@ export class CacheService { ...@@ -131,7 +132,13 @@ export class CacheService {
if(this.cache.size > 0) { if(this.cache.size > 0) {
if(!this.timerSubscription) { if(!this.timerSubscription) {
console.log("adding clearing timer"); console.log("adding clearing timer");
this.timerSubscription = this.timerObservable.subscribe(v => {this.cleanExpired();});
this.zone.runOutsideAngular(() => {
this.timerSubscription = this.timerObservable.subscribe(v => {
this.cleanExpired();
});
});
} }
} else { } else {
if(this.timerSubscription) { if(this.timerSubscription) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!