Advanced Features > DHTML Thin-Client Support in JViews Framework  > Tiling > Server-Side Caching

Use IlvTileManager to manage caching on the server side.

The Tile Manager

Static or dynamic layers can be used in conjunction with tiled views on the client side.

Static layers can be cached or pregenerated on the server. Cached tiles are part of layers that are not expected to change within the application lifecycle, as, for example, in a background map. Cached tiles can be retrieved through a tile manager.

Dynamic layers are likely to change between requests to the server, such as labeling or network display.

The tile manager, an instance of IlvTileManager, stores and retrieves tiles on the server side. IlvManagerServlet can take advantage of such a tile manager if one is installed on the servlet.

Basic Mechanism of the Tile Manager

When an image request is received by the servlet, if a tile that matches the current request is managed by the tile manager, it will return this cached tile instead of generating a new image from IlvManagerView.

If a tile is not yet managed by the tile manager, generate the image from IlvManagerView and ask the tile manager to manage it for future access.

When IlvManagerServletSupport responds to an image request, it uses the tile manager as follows:

if (useTileManager(request)) {
   IlvTileManager tm = getTileManager(request);
   if (tm != null) {
    Object key = getKey(request);
    BufferedImage image = tm.getImage(key);
    if (image == null) {
      image = doGenerateImageImpl( ... );
      tm.putImage(key, image);
     }
    return image;
   }
  }
  return doGenerateImageImpl( ... );

Code Sample 7.11 Use of the Tile Manager in a Response to an Image Request

The tile manager is invoked by default if the request contains a parameter of the form tile=true. If the request contains such a parameter, useTileManager(request) will return true. You can override the useTileManager method to call the tile manager in other situations.

If a tile manager is installed, it will be retrieved and a key object will be constructed from the request to reference the tile. Then, an attempt is made to retrieve a tile from the tile manager. If the attempt is successful, the tile is returned as the response to the request.

If no tile is retrieved, an image will be constructed through the normal image generation process. This image is passed to the tile manager for use in future retrievals.

The tile manager is not installed by default in an IlvManagerServletSupport object. You need to subclass it to install a tile manager.

The method to override is getTileManager. By default, this method returns null.

protected IlvTileManager getTileManager(HttpServletRequest request) 
                throws ServletException {
   return null;
}

Code Sample 7.12 Default Setting of getTileManager to Override

A default implementation of the tile manager is supplied. This implementation stores tiles on disk. You can use it to develop your own implementation of the getTileManager method.

protected IlvTileManager getTileManager(HttpServletRequest request) 
                throws ServletException {
   ServletContext context = request.getSession().getServletContext();
   IlvTileManager tileManager =      
    (IlvTileManager)context.getAttribute("tileManagerKey");
   if(tileManager == null) {
     tileManager = new IlvFileTileManager(getBase(), getMaxCacheSize(),
      getMinCacheSize());
     context.setAttribute("tileManagerKey", tileManager);
   }
   return tileManager;
}

Code Sample 7.13 Default Implementation of the Tile Manager

In this implementation you need to provide:

The tile manager is stored and retrieved from the ServletContext, so that the same tile manager is used for the same application. You can use a different strategy for storing and retrieving the tile manager.

You can also customize the reading and writing of tiles and the name of the file that is generated for each tile. This default implementation of the tile manager constructs a file name of the form x_y_width_height.jpg, where x, y, width, and height are the manager coordinates of the image request passed as the bbox attribute of the request.

This file is stored in and retrieved from the base directory provided when the IlvFileTileManager is constructed. This customization can be performed through the IlvFileTileURLFactory, which is responsible for building a URL from the key that identifies the tile. The default key is a Rectangle2D.Double object, which is created from the bbox parameter of the request.