Search code examples
javageoserver

Is there a way to permanently remove a tile "programmatically" (Java) from caching in GeoServer?


I'm working with GeoServer and a Java backend. I am able to reset a tile's cache using the Rest API and to prevent any further cahing by removing the tile permanently from GeoServer's GUI (Tile Caching -> Tile Layers -> Check the tile -> Click on "Remove selected cached layers").

I would like to automatize the process and do it from back-end side. I tried truncate operations, dug in the rest api as well as Java objects but haven't been able to figure how.

Is is possible to permanently remove a tile from caching using Java? If yes, how?

Thank you for your help.


Solution

  • If you are trying to avoid caching a layer at all (rather than truncating a layer's cache) then you need to visit its GWC REST endpoint:

    http://localhost:8080/geoserver/gwc/rest/layers/zoomstack:airports.xml
    

    which will give you a file like:

    <GeoServerLayer>
      <id>LayerInfoImpl-36bac688:1666e6c28d4:-7ffd</id>
      <enabled>true</enabled>
      <inMemoryCached>true</inMemoryCached>
      <name>zoomstack:airports</name>
      <mimeFormats>
        <string>image/png</string>
        <string>image/jpeg</string>
      </mimeFormats>
      <gridSubsets>
        <gridSubset>
          <gridSetName>osgb</gridSetName>
        </gridSubset>
        <gridSubset>
          <gridSetName>EPSG:900913</gridSetName>
        </gridSubset>
        <gridSubset>
          <gridSetName>EPSG:4326</gridSetName>
        </gridSubset>
      </gridSubsets>
      <metaWidthHeight>
        <int>4</int>
        <int>4</int>
      </metaWidthHeight>
      <expireCache>0</expireCache>
      <expireClients>0</expireClients>
      <parameterFilters>
        <styleParameterFilter>
          <key>STYLES</key>
          <defaultValue/>
        </styleParameterFilter>
      </parameterFilters>
      <gutter>0</gutter>
    </GeoServerLayer>
    

    You can then change <enabled>true</enabled> to <enabled>false</enabled> and PUT it back to the server.