Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.

Commit cc979d5

Browse files
committed
fix(performance): add cache on nominatim,osrm,taginfo
1 parent d31c652 commit cc979d5

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

src/nominatim/nominatim.service.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class NominatimAPI{
1212
constructor($http, options) {
1313
this.url = options.url;
1414
this.$http = $http;
15+
this.cache = true;
16+
if (options.cache === false) {
17+
this.cache = false;
18+
}
1519
}
1620

1721
/**
@@ -34,7 +38,8 @@ class NominatimAPI{
3438
params.format = 'json';
3539
}
3640
var config = {
37-
params: params
41+
params: params,
42+
cache: this.cache
3843
};
3944
let url = this.url + '/search';
4045
return this.$http.get(url, config);
@@ -60,7 +65,8 @@ class NominatimAPI{
6065
params.format = 'json';
6166
}
6267
var config = {
63-
params: params
68+
params: params,
69+
cache: this.cache
6470
};
6571
let url = this.url + '/reverse';
6672
return this.$http.get(url, config);
@@ -85,7 +91,8 @@ class NominatimAPI{
8591
params.format = 'json';
8692
}
8793
var config = {
88-
params: params
94+
params: params,
95+
cache: this.cache
8996
};
9097
let url = this.url + '/lookup';
9198
return this.$http.get(url, config);

src/osrm/osrm.service.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ class OSRMAPI{
1313
this.url = options.url;
1414
this.$http = $http;
1515
this.$q = $q;
16+
this.cache = true;
17+
if (options.cache === false) {
18+
this.cache = false;
19+
}
1620
}
1721
/**
1822
* internal get request to the remote API
1923
* @param {string} service
2024
* @param {string} version
2125
* @param {string} profile
2226
* @param {string|Object} coordinates
23-
* the string format is {longitude},{latitude};{longitude},{latitude}[;{longitude},{latitude} ...]
27+
* the string format is
28+
* {longitude},{latitude};{longitude},{latitude}[;{longitude},{latitude} ...]
2429
* @param {Object} options
2530
*/
2631
get(service, version, profile, coordinates, options) {
@@ -29,7 +34,7 @@ class OSRMAPI{
2934
_coordinates = coordinates.join(';');
3035
}
3136
var url = `${this.url}/${service}/${version}/${profile}/${_coordinates}`;
32-
return this.$http.get(url, {params: options});
37+
return this.$http.get(url, {params: options, cache: this.cache});
3338
}
3439
/**
3540
* neareset service

src/taginfo/taginfo.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
import osmTagInfoAPI from './taginfo.service';
55

66
var osmTagInfoModule = angular.module('osm.taginfo', [])
7-
.service('osmTagInfoAPI', osmTagInfoAPI);
7+
.provider('osmTagInfoAPI', function osmTagInfoAPIProvider () {
8+
this.options = {
9+
url: 'https://taginfo.openstreetmap.org/api/4'
10+
};
11+
this.$get = function osmTagInfoAPIFactory($http, $q) {
12+
return new osmTagInfoAPI($http, $q, this.options);
13+
};
14+
this.$get.$inject = ['$http', '$q'];
15+
});
816

917
export default osmTagInfoModule;

src/taginfo/taginfo.service.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ class TagInfoAPI{
99
* @param {Object} $http angular $http service
1010
* @param {Object} $q angular $q service
1111
*/
12-
constructor($http, $q) {
12+
constructor($http, $q, options) {
1313
this.$http = $http;
1414
this.$q = $q;
15-
this.url = 'https://taginfo.openstreetmap.org/api/4';
15+
this.url = options.url;
16+
this.cache = true;
17+
if (options.cache === false) {
18+
this.cache = false;
19+
}
1620
}
1721
/**
1822
* internal get request to the remote API
@@ -22,6 +26,12 @@ class TagInfoAPI{
2226
*/
2327
get(method, config) {
2428
var deferred = this.$q.defer();
29+
if (!config) {
30+
config = {};
31+
}
32+
if (config.cache === undefined) {
33+
config.cache = this.cache;
34+
}
2535
this.$http.get(this.url + method, config).then(
2636
function (data) {
2737
deferred.resolve(data.data);

0 commit comments

Comments
 (0)