Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1229cf09
authored
Feb 17, 2017
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed cache from angular zone detection, so it does not trigger change detection on cleanup
1 parent
c5184859
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
4 deletions
code/moya-angular/src/app/app.component.ts
code/moya-angular/src/app/moya-rest/moya-rest.module.ts
code/moya-angular/src/app/moya-rest/services/cache.service.ts
code/moya-angular/src/app/app.component.ts
View file @
1229cf0
...
...
@@ -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
}
...
...
code/moya-angular/src/app/moya-rest/moya-rest.module.ts
View file @
1229cf0
import
{
NgModule
,
ModuleWithProviders
}
from
'@angular/core'
;
import
{
NgModule
,
ModuleWithProviders
,
NgZone
}
from
'@angular/core'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
HttpModule
}
from
"@angular/http"
;
import
{
MoyaRestService
}
from
"./services/moya-rest.service"
;
...
...
code/moya-angular/src/app/moya-rest/services/cache.service.ts
View file @
1229cf0
import
{
Injectable
}
from
"@angular/core"
;
import
{
Injectable
,
NgZone
}
from
"@angular/core"
;
import
{
Observable
,
Subscriber
,
Subscription
}
from
"rxjs"
;
...
...
@@ -45,8 +45,9 @@ export class CacheService {
// TODO: timed clearup for cache to save memory
constructor
()
{
constructor
(
private
zone
:
NgZone
)
{
this
.
cache
=
new
Map
<
string
,
CachedItem
>
();
this
.
timerObservable
=
Observable
.
timer
(
30000
,
30000
);
// afther 0.5min, every 0.5min.
}
...
...
@@ -131,7 +132,13 @@ export class CacheService {
if
(
this
.
cache
.
size
>
0
)
{
if
(
!
this
.
timerSubscription
)
{
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
{
if
(
this
.
timerSubscription
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment