Package org.apache.pdfbox.pdmodel
Class DefaultResourceCache
java.lang.Object
org.apache.pdfbox.pdmodel.DefaultResourceCache
- All Implemented Interfaces:
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
3. This may happen if resources are shared among several pages. This kind of stable caching is
enabled by default and can be deactivated.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<COSObject, SoftReference<PDColorSpace>> private final Map<COSObject, SoftReference<PDExtendedGraphicsState>> private final Map<COSObject, SoftReference<PDFont>> private static final intprivate final Map<COSObject, SoftReference<PDAbstractPattern>> private final Map<COSObject, SoftReference<PDPropertyList>> private final Map<COSObject, SoftReference<PDShading>> private final booleanprivate final Map<COSObject, SoftReference<PDXObject>> -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.DefaultResourceCache(boolean enableStableCache) Constructor providing a parameter to enable/disable the stable object cache. -
Method Summary
Modifier and TypeMethodDescriptiongetColorSpace(COSObject indirect) Returns the color space resource for the given indirect object, if it is in the cache.getExtGState(COSObject indirect) Returns the extended graphics state resource for the given indirect object, if it is in the cache.Returns the font resource for the given indirect object, if it is in the cache.getPattern(COSObject indirect) Returns the pattern resource for the given indirect object, if it is in the cache.getProperties(COSObject indirect) Returns the property list resource for the given indirect object, if it is in the cache.getShading(COSObject indirect) Returns the shading resource for the given indirect object, if it is in the cache.getXObject(COSObject indirect) Returns the XObject resource for the given indirect object, if it is in the cache.voidput(COSObject indirect, PDPropertyList propertyList) Puts the given indirect property list resource in the cache.voidPuts the given indirect font resource in the cache.voidput(COSObject indirect, PDColorSpace colorSpace) Puts the given indirect color space resource in the cache.voidput(COSObject indirect, PDAbstractPattern pattern) Puts the given indirect pattern resource in the cache.voidPuts the given indirect XObject resource in the cache.voidPuts the given indirect shading resource in the cache.voidput(COSObject indirect, PDExtendedGraphicsState extGState) Puts the given indirect extended graphics state resource in the cache.removeColorSpace(COSObject indirect) Removes the given indirect color space resource from the cache.removeExtState(COSObject indirect) Removes the given indirect extended graphics state resource from the cache.removeFont(COSObject indirect) Removes the given indirect font resource from the cache.removePattern(COSObject indirect) Removes the given indirect pattern resource from the cache.removeProperties(COSObject indirect) Removes the given indirect property list resource from the cache.removeShading(COSObject indirect) Removes the given indirect shading resource from the cache.removeXObject(COSObject indirect) Removes the given indirect XObject resource from the cache.
-
Field Details
-
maxRemovals
private static final int maxRemovals- See Also:
-
stableCacheEnabled
private final boolean stableCacheEnabled -
fonts
-
removedFonts
-
stableFonts
-
colorSpaces
-
removedColorSpaces
-
stableColorSpaces
-
xobjects
-
removedXObjects
-
stableXObject
-
extGStates
-
removedExtGStates
-
stableExtGStates
-
shadings
-
removedShadings
-
stableShadings
-
patterns
-
removedPatterns
-
stablePatterns
-
properties
-
removedProperties
-
stableProperties
-
-
Constructor Details
-
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 Details
-
getFont
Description copied from interface:ResourceCacheReturns the font resource for the given indirect object, if it is in the cache.- Specified by:
getFontin interfaceResourceCache- Parameters:
indirect- the indirect reference of the font to be returned- Returns:
- the cached instance of the referenced font, if available
-
put
Description copied from interface:ResourceCachePuts the given indirect font resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the font to be cachedfont- the font to be cached
-
removeFont
Description copied from interface:ResourceCacheRemoves the given indirect font resource from the cache.- Specified by:
removeFontin interfaceResourceCache- Parameters:
indirect- the indirect reference of the font to be removed- Returns:
- the removed resource if present
-
getColorSpace
Description copied from interface:ResourceCacheReturns the color space resource for the given indirect object, if it is in the cache.- Specified by:
getColorSpacein interfaceResourceCache- Parameters:
indirect- the indirect reference of the colorspace to be returned- Returns:
- the cached instance of the referenced colorspace, if available
-
put
Description copied from interface:ResourceCachePuts the given indirect color space resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the colorspace to be cachedcolorSpace- the colorspace to be cached
-
removeColorSpace
Description copied from interface:ResourceCacheRemoves the given indirect color space resource from the cache.- Specified by:
removeColorSpacein interfaceResourceCache- Parameters:
indirect- the indirect reference of the color space to be removed- Returns:
- the removed resource if present
-
getExtGState
Description copied from interface:ResourceCacheReturns the extended graphics state resource for the given indirect object, if it is in the cache.- Specified by:
getExtGStatein interfaceResourceCache- 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
Description copied from interface:ResourceCachePuts the given indirect extended graphics state resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the extended graphics state to be cachedextGState- the extended graphics state to be cached
-
removeExtState
Description copied from interface:ResourceCacheRemoves the given indirect extended graphics state resource from the cache.- Specified by:
removeExtStatein interfaceResourceCache- Parameters:
indirect- the indirect reference of the extended graphics state to be removed- Returns:
- the removed resource if present
-
getShading
Description copied from interface:ResourceCacheReturns the shading resource for the given indirect object, if it is in the cache.- Specified by:
getShadingin interfaceResourceCache- Parameters:
indirect- the indirect reference of the shading to be returned- Returns:
- the cached instance of the referenced shading, if available
-
put
Description copied from interface:ResourceCachePuts the given indirect shading resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the shading to be cachedshading- the shading to be cached
-
removeShading
Description copied from interface:ResourceCacheRemoves the given indirect shading resource from the cache.- Specified by:
removeShadingin interfaceResourceCache- Parameters:
indirect- the indirect reference of the shading to be removed- Returns:
- the removed resource if present
-
getPattern
Description copied from interface:ResourceCacheReturns the pattern resource for the given indirect object, if it is in the cache.- Specified by:
getPatternin interfaceResourceCache- Parameters:
indirect- the indirect reference of the pattern to be returned- Returns:
- the cached instance of the referenced pattern, if available
-
put
Description copied from interface:ResourceCachePuts the given indirect pattern resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the pattern to be cachedpattern- the pattern to be cached
-
removePattern
Description copied from interface:ResourceCacheRemoves the given indirect pattern resource from the cache.- Specified by:
removePatternin interfaceResourceCache- Parameters:
indirect- the indirect reference of the pattern to be removed- Returns:
- the removed resource if present
-
getProperties
Description copied from interface:ResourceCacheReturns the property list resource for the given indirect object, if it is in the cache.- Specified by:
getPropertiesin interfaceResourceCache- Parameters:
indirect- the indirect reference of the property list to be returned- Returns:
- the cached instance of the referenced property list, if available
-
put
Description copied from interface:ResourceCachePuts the given indirect property list resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the property list to be cachedpropertyList- the property list to be cached
-
removeProperties
Description copied from interface:ResourceCacheRemoves the given indirect property list resource from the cache.- Specified by:
removePropertiesin interfaceResourceCache- Parameters:
indirect- the indirect reference of the property list to be removed- Returns:
- the removed resource if present
-
getXObject
Description copied from interface:ResourceCacheReturns the XObject resource for the given indirect object, if it is in the cache.- Specified by:
getXObjectin interfaceResourceCache- Parameters:
indirect- the indirect reference of the XObject to be returned- Returns:
- the cached instance of the referenced XObject, if available
-
put
Description copied from interface:ResourceCachePuts the given indirect XObject resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the XObject to be cachedxobject- the XObject to be cached
-
removeXObject
Description copied from interface:ResourceCacheRemoves the given indirect XObject resource from the cache.- Specified by:
removeXObjectin interfaceResourceCache- Parameters:
indirect- the indirect reference of the XObject to be removed- Returns:
- the removed resource if present
-