Skip to content

Commit

Permalink
feat(cache): add metadata tag to cache calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Dec 20, 2018
1 parent b051df8 commit 793d1ff
Showing 1 changed file with 2 additions and 7 deletions.
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, forkJoin, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { Cacheable } from 'ngx-cacheable';

import { WMSCapabilities, WMTSCapabilities } from 'ol/format';
import { optionsFromCapabilities } from 'ol/source/WMTS.js';
Expand Down Expand Up @@ -113,6 +114,7 @@ export class CapabilitiesService {
);
}

@Cacheable()
getCapabilities(
service: 'wms' | 'wmts',
baseUrl: string,
Expand All @@ -126,12 +128,6 @@ export class CapabilitiesService {
}
});

const url = baseUrl + '?' + params.toString();
const cached = this.capabilitiesStore.find(value => value.url === url);
if (cached !== undefined) {
return new Observable(c => c.next(cached.capabilities));
}

const request = this.http.get(baseUrl, {
params: params,
responseType: 'text'
Expand All @@ -140,7 +136,6 @@ export class CapabilitiesService {
return request.pipe(
map(res => {
const capabilities = this.parsers[service].read(res);
this.cache(url, capabilities);
return capabilities;
})
);
Expand Down

0 comments on commit 793d1ff

Please sign in to comment.