One of the main uses of GeoServer is that it acts as a map server. It gets your data, applies styles and other transformations, and outputs pretty maps.
Every time a client requests a map to visualize, GeoServer has to perform a complex set of operations, load data, apply styles, render the result to a bitmap, and push it back to the client who performed the request. As your web application gains popularity, more and more concurrent requests will add and you could run out of resource to satisfy them all.
Having to build the map from scratch every time seems like nonsense, especially if your web application does not offer the user the possibility to modify styles for layers. In many cases, the styles are defined once and never, or very rarely, updated. So, your GeoServer instance will render lots of identical maps.
Indeed, when you are requesting a map to GeoServer, the chances are that the same map was produced before. We need a procedure to store maps and to retrieve them when required and match them for equality. This is a more general problem and is not specifically linked to GeoServer. Several systems to implement map caching exist. Earlier, GeoServer releases didn't include any caching mechanism and you had to set a software in front of GeoServer intercepting map requests and forward only those that can't get a hit from the cache to GeoServer.
In this recipe, you will learn how to use the included GeoWebCache.
webapps
folder inside the Apache Tomcat installation folder:$ cd /opt/Tomcat7042/webapps/
geoserver/WEB-INF
folder:$ cd geoserver/WEB-INF/
web.xml
file and locate the line that contains the following code:<display-name>GeoServer</display-name>
param-value
is valorized with a folder path valid on Linux (use the appropriate syntax on Windows):<!-- Setting GeoWebCache folder --> <context-param> <param-name>GEOWEBCACHE_CACHE_DIR</param-name> <param-value>/opt/gwc</param-value> </context-param>
web.xml
file on startup, so any change inside it is effective only after an application reload or a servlet container restarts.http://localhost:8080/manager/html/list
. Locate GeoServer in the application list and click on the Reload button on the left.EPSG:4326/jpeg
. A new map preview will show up in the browser window.You configured the storage location for your tiles. By default, GeoWebCache stores them in the temp
folder located inside the Tomcat installation location. For the production site, it is a good idea to use a folder on a different device. Also, try to avoid storing tiles on the same disk where the data is stored.
As map requests reach GeoServer, the size of the cache may grow very fast and can also fill your disk if you are caching a lot of layers. You may want to set a disk quota to avoid filesystem corruption.
You may also want to override the default setting of GeoServer that sets all layers to be cached. Cache is very useful with static data; if you have layers with data source updating very frequently, having them cached is a waste of time and may produce maps that do not reflect the actual state of the data.
There are several configuration parameters for GeoWebCache. We will explore them in detail in Chapter 6, Automating GeoServer Configurations.
3.144.19.243