org.apache.pdfbox.pdmodel

## Class DefaultResourceCache

- java.lang.Object
- - org.apache.pdfbox.pdmodel.DefaultResourceCache

All Implemented Interfaces:
  ResourceCache

    public class DefaultResourceCache
    extends Object
    implements ResourceCache

A resource cached based on SoftReference, retains resources until memory pressure causes them to be garbage collected. Cached resources may be removed pro actively. Resources which are removed and added several times, can't be removed after hitting the threshold of . This may happen if resources are shared among several pages. This kind of stable caching is enabled by default and can be deactivated.

Author:
  John Hewson

### Constructor Summary

Constructors
Constructor and Description
`DefaultResourceCache()` Default constructor.
`DefaultResourceCache(boolean enableStableCache)` Constructor providing a parameter to enable/disable the stable object cache.

### Method Summary

All Methods Instance Methods Concrete Methods
`PDColorSpace` `getColorSpace(COSObject indirect)` Returns the color space resource for the given indirect object, if it is in the cache.
`PDExtendedGraphicsState` `getExtGState(COSObject indirect)` Returns the extended graphics state resource for the given indirect object, if it is in the cache.
`PDFont` `getFont(COSObject indirect)` Returns the font resource for the given indirect object, if it is in the cache.
`PDAbstractPattern` `getPattern(COSObject indirect)` Returns the pattern resource for the given indirect object, if it is in the cache.
`PDPropertyList` `getProperties(COSObject indirect)` Returns the property list resource for the given indirect object, if it is in the cache.
`PDShading` `getShading(COSObject indirect)` Returns the shading resource for the given indirect object, if it is in the cache.
`PDXObject` `getXObject(COSObject indirect)` Returns the XObject resource for the given indirect object, if it is in the cache.
`void` `put(COSObject indirect, PDAbstractPattern pattern)` Puts the given indirect pattern resource in the cache.
`void` `put(COSObject indirect, PDColorSpace colorSpace)` Puts the given indirect color space resource in the cache.
`void` `put(COSObject indirect, PDExtendedGraphicsState extGState)` Puts the given indirect extended graphics state resource in the cache.
`void` `put(COSObject indirect, PDFont font)` Puts the given indirect font resource in the cache.
`void` `put(COSObject indirect, PDPropertyList propertyList)` Puts the given indirect property list resource in the cache.
`void` `put(COSObject indirect, PDShading shading)` Puts the given indirect shading resource in the cache.
`void` `put(COSObject indirect, PDXObject xobject)` Puts the given indirect XObject resource in the cache.
`PDColorSpace` `removeColorSpace(COSObject indirect)` Removes the given indirect color space resource from the cache.
`PDExtendedGraphicsState` `removeExtState(COSObject indirect)` Removes the given indirect extended graphics state resource from the cache.
`PDFont` `removeFont(COSObject indirect)` Removes the given indirect font resource from the cache.
`PDAbstractPattern` `removePattern(COSObject indirect)` Removes the given indirect pattern resource from the cache.
`PDPropertyList` `removeProperties(COSObject indirect)` Removes the given indirect property list resource from the cache.
`PDShading` `removeShading(COSObject indirect)` Removes the given indirect shading resource from the cache.
`PDXObject` `removeXObject(COSObject indirect)` Removes the given indirect XObject resource from the cache.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DefaultResourceCache

    public DefaultResourceCache()

Default constructor.

#### DefaultResourceCache

    public DefaultResourceCache(boolean enableStableCache)

Constructor providing a parameter to enable/disable the stable object cache.

Parameters:
  `enableStableCache` - enables/disables the stable object cache

### Method Detail

#### getFont

    public PDFont getFont(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the font resource for the given indirect object, if it is in the cache.

Specified by:
  `getFont` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the font to be returned
Returns:
  the cached instance of the referenced font, if available

#### put

    public void put(COSObject indirect,
                    PDFont font)

Description copied from interface: `ResourceCache`
Puts the given indirect font resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the font to be cached
  `font` - the font to be cached

#### removeFont

    public PDFont removeFont(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect font resource from the cache.

Specified by:
  `removeFont` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the font to be removed
Returns:
  the removed resource if present

#### getColorSpace

    public PDColorSpace getColorSpace(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the color space resource for the given indirect object, if it is in the cache.

Specified by:
  `getColorSpace` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the colorspace to be returned
Returns:
  the cached instance of the referenced colorspace, if available

#### put

    public void put(COSObject indirect,
                    PDColorSpace colorSpace)

Description copied from interface: `ResourceCache`
Puts the given indirect color space resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the colorspace to be cached
  `colorSpace` - the colorspace to be cached

#### removeColorSpace

    public PDColorSpace removeColorSpace(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect color space resource from the cache.

Specified by:
  `removeColorSpace` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the color space to be removed
Returns:
  the removed resource if present

#### getExtGState

    public PDExtendedGraphicsState getExtGState(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the extended graphics state resource for the given indirect object, if it is in the cache.

Specified by:
  `getExtGState` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the extended graphics state to be returned
Returns:
  the cached instance of the referenced extended graphics state, if available

#### put

    public void put(COSObject indirect,
                    PDExtendedGraphicsState extGState)

Description copied from interface: `ResourceCache`
Puts the given indirect extended graphics state resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the extended graphics state to be cached
  `extGState` - the extended graphics state to be cached

#### removeExtState

    public PDExtendedGraphicsState removeExtState(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect extended graphics state resource from the cache.

Specified by:
  `removeExtState` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the extended graphics state to be removed
Returns:
  the removed resource if present

#### getShading

    public PDShading getShading(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the shading resource for the given indirect object, if it is in the cache.

Specified by:
  `getShading` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the shading to be returned
Returns:
  the cached instance of the referenced shading, if available

#### put

    public void put(COSObject indirect,
                    PDShading shading)

Description copied from interface: `ResourceCache`
Puts the given indirect shading resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the shading to be cached
  `shading` - the shading to be cached

#### removeShading

    public PDShading removeShading(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect shading resource from the cache.

Specified by:
  `removeShading` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the shading to be removed
Returns:
  the removed resource if present

#### getPattern

    public PDAbstractPattern getPattern(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the pattern resource for the given indirect object, if it is in the cache.

Specified by:
  `getPattern` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the pattern to be returned
Returns:
  the cached instance of the referenced pattern, if available

#### put

    public void put(COSObject indirect,
                    PDAbstractPattern pattern)

Description copied from interface: `ResourceCache`
Puts the given indirect pattern resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the pattern to be cached
  `pattern` - the pattern to be cached

#### removePattern

    public PDAbstractPattern removePattern(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect pattern resource from the cache.

Specified by:
  `removePattern` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the pattern to be removed
Returns:
  the removed resource if present

#### getProperties

    public PDPropertyList getProperties(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the property list resource for the given indirect object, if it is in the cache.

Specified by:
  `getProperties` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the property list to be returned
Returns:
  the cached instance of the referenced property list, if available

#### put

    public void put(COSObject indirect,
                    PDPropertyList propertyList)

Description copied from interface: `ResourceCache`
Puts the given indirect property list resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the property list to be cached
  `propertyList` - the property list to be cached

#### removeProperties

    public PDPropertyList removeProperties(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect property list resource from the cache.

Specified by:
  `removeProperties` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the property list to be removed
Returns:
  the removed resource if present

#### getXObject

    public PDXObject getXObject(COSObject indirect)

Description copied from interface: `ResourceCache`
Returns the XObject resource for the given indirect object, if it is in the cache.

Specified by:
  `getXObject` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the XObject to be returned
Returns:
  the cached instance of the referenced XObject, if available

#### put

    public void put(COSObject indirect,
                    PDXObject xobject)

Description copied from interface: `ResourceCache`
Puts the given indirect XObject resource in the cache.

Specified by:
  `put` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the XObject to be cached
  `xobject` - the XObject to be cached

#### removeXObject

    public PDXObject removeXObject(COSObject indirect)

Description copied from interface: `ResourceCache`
Removes the given indirect XObject resource from the cache.

Specified by:
  `removeXObject` in interface `ResourceCache`
Parameters:
  `indirect` - the indirect reference of the XObject to be removed
Returns:
  the removed resource if present