Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9dac95c2
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
610b0988
Hide 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 @
9dac95c
...
...
@@ -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 @
9dac95c
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 @
9dac95c
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