Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| xmlgraphics-commons 2.3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.xmlgraphics.image.loader.cache
Class ImageCache

    java.lang.Object
      org.apache.xmlgraphics.image.loader.cache.ImageCache

    public class ImageCache

extends java.lang.Object

This class provides a cache for images. The main key into the images is the original URI the image was accessed with.

Don't use one ImageCache instance in the context of multiple base URIs because relative URIs would not work correctly anymore.

By default, the URIs of inaccessible images are remembered but these entries are discarded after 60 seconds (which causes a retry next time the same URI is requested). This allows to counteract performance loss when accessing invalid or temporarily unavailable images over slow connections.

Field Summary
`protected static org.apache.commons.logging.Log` | `log` logger

Constructor Summary
`ImageCache()` Default constructor with default settings.
`ImageCache(org.apache.xmlgraphics.image.loader.cache.TimeStampProvider timeStampProvider, ExpirationPolicy invalidURIExpirationPolicy)` Constructor for customized behaviour and testing.

Method Summary
`void` | `clearCache()` Clears the image cache (all ImageInfo and Image objects).
`void` | `doHouseKeeping()` Triggers some house-keeping, i.e.
`Image` | `getImage(ImageInfo info, ImageFlavor flavor)` Returns an image from the cache or null if it wasn't found.
`Image` | `getImage(java.lang.String uri, ImageFlavor flavor)` Returns an image from the cache or null if it wasn't found.
`protected ImageInfo` | `getImageInfo(java.lang.String uri)` Returns an ImageInfo instance from the cache or null if none is found.
`boolean` | `isInvalidURI(java.lang.String uri)` Indicates whether a URI has previously been identified as an invalid URI.
`ImageInfo` | `needImageInfo(java.lang.String uri, ImageSessionContext session, ImageManager manager)` Returns an ImageInfo instance for a given URI.
`void` | `putImage(Image img)` Registers an image with the cache.
`protected void` | `putImageInfo(ImageInfo info)` Registers an ImageInfo instance with the cache.
`void` | `setCacheListener(ImageCacheListener listener)` Sets an ImageCacheListener instance so the events in the image cache can be observed.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    protected static final org.apache.commons.logging.Log log

  logger

Constructor Detail

### ImageCache

    public ImageCache()

  Default constructor with default settings.

### ImageCache

    public ImageCache(org.apache.xmlgraphics.image.loader.cache.TimeStampProvider timeStampProvider,
                      ExpirationPolicy invalidURIExpirationPolicy)

  Constructor for customized behaviour and testing.

  Parameters:
    `timeStampProvider` - the time stamp provider to use
    `invalidURIExpirationPolicy` - the expiration policy for invalid URIs

Method Detail

### setCacheListener

    public void setCacheListener(ImageCacheListener listener)

  Sets an ImageCacheListener instance so the events in the image cache can be observed.

  Parameters:
    `listener` - the listener instance

### needImageInfo

    public ImageInfo needImageInfo(java.lang.String uri,
                                   ImageSessionContext session,
                                   ImageManager manager)
                            throws ImageException,
                                   java.io.IOException

  Returns an ImageInfo instance for a given URI.

  Parameters:
    `uri` - the image's URI
    `session` - the session context
    `manager` - the ImageManager handling the images
  Returns:
    the ImageInfo instance
  Throws:
    `ImageException` - if an error occurs while parsing image data
    `java.io.IOException` - if an I/O error occurs while loading image data

### isInvalidURI

    public boolean isInvalidURI(java.lang.String uri)

  Indicates whether a URI has previously been identified as an invalid URI.

  Parameters:
    `uri` - the image's URI
  Returns:
    true if the URI is invalid

### getImageInfo

    protected ImageInfo getImageInfo(java.lang.String uri)

  Returns an ImageInfo instance from the cache or null if none is found.

  Parameters:
    `uri` - the image's URI
  Returns:
    the ImageInfo instance or null if the requested information is not in the cache

### putImageInfo

    protected void putImageInfo(ImageInfo info)

  Registers an ImageInfo instance with the cache.

  Parameters:
    `info` - the ImageInfo instance

### getImage

    public Image getImage(ImageInfo info,
                          ImageFlavor flavor)

  Returns an image from the cache or null if it wasn't found.

  Parameters:
    `info` - the ImageInfo instance representing the image
    `flavor` - the requested ImageFlavor for the image
  Returns:
    the requested image or null if the image is not in the cache

### getImage

    public Image getImage(java.lang.String uri,
                          ImageFlavor flavor)

  Returns an image from the cache or null if it wasn't found.

  Parameters:
    `uri` - the image's URI
    `flavor` - the requested ImageFlavor for the image
  Returns:
    the requested image or null if the image is not in the cache

### putImage

    public void putImage(Image img)

  Registers an image with the cache.

  Parameters:
    `img` - the image

### clearCache

    public void clearCache()

  Clears the image cache (all ImageInfo and Image objects).

### doHouseKeeping

    public void doHouseKeeping()

  Triggers some house-keeping, i.e. removes stale entries.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| xmlgraphics-commons 2.3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 1999-2018 The Apache Software Foundation. All Rights Reserved.