Caching results can improve the performance of an application and reduce the server load a lot. Please note the difference between server-side and client-side caching, both of which are described below.
Map tiles can be cached on the server side, instead of redrawing the tiles for every request. There are multiple proxy and cache technologies and products available. Because of ist simple configuration and its great spread, we describe a tile cache implementation based on the nginx HTTP server.
Download the latest nginx version and install it.
events {
worker_connections 1024;
}
http {
#configure location and size of the cache
proxy_cache_path /opt/xserver-tile-cache levels=1:2 keys_zone=one:10m max_size=5g;
proxy_temp_path /opt/xserver-tile-cache/tmp;
#define a exclusion rule for dynamic map data like PTV_TrafficIncidents
map $arg_layers $ignore_cache {
default 0;
~(.*)PTV_TrafficIncidents(.*) 1;
}
server {
#public port of the cache/xserver proxy
listen 80;
#location definition for all xmap rest requests
location /services/rest/XMap/ {
#cache configuration
expires 24h;
proxy_cache_bypass $ignore_cache;
proxy_no_cache $ignore_cache;
proxy_cache one;
proxy_ignore_headers Cache-Control;
proxy_cache_valid any 24h;
proxy_pass http://localhost:50000;
}
#location definition for all other requests
location / {
#forward the requests to the xserver backend
proxy_pass http://localhost:50000;
}
}
}
Redundant requests can be served from the client's cache, which reduces the workload for the server. For the Map Tile API and Routing REST requests, the PTV xServer 2 can set HTTP response header directives accordingly.
The HTTP response header directives set in the RESTREST (Representational State Transfer) represents a World Wide Web paradigm, consisting of constraints to the design of components which results in a better performance and maintainability. responses can be configured in the xserver.conf
:
core {
[...]
cacheControl {
maximumAge = 86400
}
}
By default, the maximum age for cached responses on client-side is set to 24h.
With the default settings shown above, the cache header of the response to the xMap tile request http://hostname:50000/services/rest/XMap/tile/13/4238/2790
is valid for 24 hours:
cache-control: public, max-age=86400
content-length: 7705
content-type: image/png
[...]
On the other hand, xMap and xRoute REST requests with
http://hostname:50000/services/rest/XMap/tile/13/4235/2792?layers=PTV_TrafficIncidents
) orhttp://hostname:50000/services/rest/XRoute/routeA route corresponds to a path of a vehicle through the underlying transport network. The main attributes of a route are the distance and the time that the vehicle travels along the path./6.12/49.58/6.12/49.58?timeConsideration=SNAPSHOT
):
may have dynamically changing data and therefore will not be cached:
cache-control: no-cache, no-store, must-revalidate
content-length: 1615
content-type: image/png
[...]