[GIS] How to set Tomcat to completely prevent browser from caching the PBF vector tile

browsercachegeoservertomcatvector-tiles

I need to publish a geometry table (in PostGIS) as a layer of vector tiles (in PBF format) in GeoServer. As the table is dynamically written by a production web app, i need to set the layer's caching as disable in both server and client.
For that reason, in the layer's Tile Caching in Geoserver, I set -1 in both:

  • Expire server cache after n seconds
  • Expire client cache after n seconds

like the following picture:

enter image description here

However, my observation shows that the above only prevents server cache and not client cache, as newly added points will only be shown in my OpenLayers page when any of the following applies:

  1. when the browser is cleared from cache
  2. when the tile is newly received from server (not from cache)

So i dig in more references especially on how to set Tomcat to prevent client from caching. Based on a reference I tried to add ExpiresFilter in the Tomcat's web.xml:

<filter-name>ExpiresFilter</filter-name>
<filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
<init-param>
  <param-name>ExpiresByType application/x-protobuf</param-name>
  <param-value>access plus 0 seconds</param-value>
</init-param>

The result is now each tile has new 4 headers in Response Headers: max-age=0, Expires date (with expected value), and 2 more headers; like the following image.

enter image description here

Now the problem: page refresh in browser gets these tiles from browser cache, with HTTP 304 status, and the new 4 headers are now gone; like the following image.

enter image description here

In this situation, any newly added points in my PostGIS table will only appear in OpenLayers when the corresponding tile never gets to browser before.

Question:

  • Is this normal?
  • How to completely prevent browser from caching my PBF vector tile?

My ecosystem:

  • OpenLayers 5.1.3
  • GeoServer 2.13.2 on Tomcat 8.5.32
  • Windows 10 Pro 64-bit
  • PostgreSQL 9.6.1 with PostGIS 2.3
  • browser: FireFox, IE

Best Answer

You might be better off avoiding GWC and hitting the WMS end point directly and modifying the HTTP Cache settings on the Layer Publishing tab. I'm not sure if that setting is still used if you go through GWC. Also using vector tiles seems like a lot of work for a rapidly changing data set, you might do better with simple png images.

enter image description here

Related Question