Package org.opencms.loader
Class CmsS3ImageCache
java.lang.Object
org.opencms.loader.CmsS3ImageCache
- All Implemented Interfaces:
AutoCloseable,I_CmsImageCache,I_CmsImageCacheAccessMetadataProvider
public class CmsS3ImageCache
extends Object
implements I_CmsImageCache, I_CmsImageCacheAccessMetadataProvider
S3 based storage for generated image cache entries.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opencms.loader.I_CmsImageCache
I_CmsImageCache.I_CmsImageCacheEntryVisitor -
Constructor Summary
ConstructorsConstructorDescriptionCmsS3ImageCache(CmsS3ClientConfiguration configuration) Creates a new image cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all image cache entries.voidclear(int deleteBatchSize) Clears the image cache using S3 multi-object delete requests.voidclose()Closes the image cache and releases associated resources.voidDeletes an image cache entry.deleteBatch(List<String> keys) Deletes image cache entries with one S3 multi-object request.booleanReturns if the image cache entry exists.booleanPerforms an authoritative existence check which does not rely on locally cached positive metadata.longReturns the image cache entry length.getMetadata(String key) Loads metadata for a single image cache entry.Returns recently observed metadata for an entry without accessing the backend.protected voidinitClient(I_CmsS3Client s3Client) Initializes the S3 client.booleanRenews an image cache entry by conditionally copying the S3 object onto itself.booleanReturns if range delivery is supported.voidvisitEntries(String prefix, I_CmsImageCache.I_CmsImageCacheEntryVisitor visitor) Visits image cache entries whose normalized keys start with the given prefix.voidVisits all image cache entries.voidvisitEntriesWithMetadata(String prefix, I_CmsS3Client.I_CmsS3ObjectMetadataVisitor visitor) Visits image cache entries with the given cache key prefix and metadata returned directly by the S3 listing.voidVisits image cache entries with metadata returned directly by the S3 listing.voidWrites an image cache entry.voidwriteRangeTo(String key, long start, long length, OutputStream out) Writes an image cache entry byte range to the output stream.voidwriteTo(String key, OutputStream out) Writes an image cache entry to the output stream.
-
Constructor Details
-
CmsS3ImageCache
Creates a new image cache.- Parameters:
configuration- the S3 configuration- Throws:
Exception- if the configured bucket can not be accessed
-
-
Method Details
-
clear
Description copied from interface:I_CmsImageCacheClears all image cache entries.- Specified by:
clearin interfaceI_CmsImageCache- Throws:
Exception- if clearing fails- See Also:
-
clear
Clears the image cache using S3 multi-object delete requests.- Parameters:
deleteBatchSize- the number of keys per request- Throws:
Exception- if listing or deleting fails
-
close
Description copied from interface:I_CmsImageCacheCloses the image cache and releases associated resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceI_CmsImageCache- Throws:
Exception- if closing fails- See Also:
-
delete
Deletes an image cache entry.- Parameters:
key- the image cache key- Throws:
Exception- if deleting fails
-
deleteBatch
Deletes image cache entries with one S3 multi-object request.- Parameters:
keys- the image cache keys- Returns:
- the per-entry result using normalized image cache keys
- Throws:
Exception- if the complete request fails
-
exists
Description copied from interface:I_CmsImageCacheReturns if the image cache entry exists.- Specified by:
existsin interfaceI_CmsImageCache- Parameters:
key- the image cache key- Returns:
trueif the image cache entry exists- Throws:
Exception- if the store access fails- See Also:
-
existsAuthoritatively
Description copied from interface:I_CmsImageCachePerforms an authoritative existence check which does not rely on locally cached positive metadata.This is used for requests which do not read the cache entry body and can therefore not detect a stale positive existence result while streaming. Implementations without a positive metadata cache can use the default implementation.
- Specified by:
existsAuthoritativelyin interfaceI_CmsImageCache- Parameters:
key- the image cache key- Returns:
trueif the image cache entry exists in the backing store- Throws:
Exception- if the store access fails- See Also:
-
getLength
Description copied from interface:I_CmsImageCacheReturns the image cache entry length.- Specified by:
getLengthin interfaceI_CmsImageCache- Parameters:
key- the image cache key- Returns:
- the image cache entry length
- Throws:
Exception- if the store access fails- See Also:
-
getMetadata
Loads metadata for a single image cache entry.- Parameters:
key- the image cache key- Returns:
- the object metadata using the normalized image cache key
- Throws:
Exception- if the metadata can not be loaded
-
getRecentAccessMetadata
Description copied from interface:I_CmsImageCacheAccessMetadataProviderReturns recently observed metadata for an entry without accessing the backend.- Specified by:
getRecentAccessMetadatain interfaceI_CmsImageCacheAccessMetadataProvider- Parameters:
key- the image cache key- Returns:
- the metadata, or
nullif no metadata is locally available - See Also:
-
renew
Renews an image cache entry by conditionally copying the S3 object onto itself.- Parameters:
key- the image cache keyexpectedRevision- the expected object revisionrenewalTime- the requested renewal time- Returns:
trueif the entry was renewed, orfalseif it no longer matched- Throws:
Exception- if renewal fails
-
supportsRangeDelivery
Description copied from interface:I_CmsImageCacheReturns if range delivery is supported.- Specified by:
supportsRangeDeliveryin interfaceI_CmsImageCache- Returns:
trueif ranges can be streamed- See Also:
-
visitEntries
Description copied from interface:I_CmsImageCacheVisits all image cache entries.- Specified by:
visitEntriesin interfaceI_CmsImageCache- Parameters:
visitor- the image cache entry visitor- Throws:
Exception- if listing fails- See Also:
-
visitEntries
public void visitEntries(String prefix, I_CmsImageCache.I_CmsImageCacheEntryVisitor visitor) throws Exception Description copied from interface:I_CmsImageCacheVisits image cache entries whose normalized keys start with the given prefix.Implementations with a prefix-aware storage backend should override this method to apply the prefix while listing. The default implementation filters the result of
I_CmsImageCache.visitEntries(I_CmsImageCacheEntryVisitor).- Specified by:
visitEntriesin interfaceI_CmsImageCache- Parameters:
prefix- the image cache key prefix, or an empty string for all entriesvisitor- the image cache entry visitor- Throws:
Exception- if listing fails- See Also:
-
visitEntriesWithMetadata
public void visitEntriesWithMetadata(I_CmsS3Client.I_CmsS3ObjectMetadataVisitor visitor) throws Exception Visits image cache entries with metadata returned directly by the S3 listing.- Parameters:
visitor- the metadata visitor- Throws:
Exception- if listing fails
-
visitEntriesWithMetadata
public void visitEntriesWithMetadata(String prefix, I_CmsS3Client.I_CmsS3ObjectMetadataVisitor visitor) throws Exception Visits image cache entries with the given cache key prefix and metadata returned directly by the S3 listing.- Parameters:
prefix- the image cache key prefix, or an empty string for all entriesvisitor- the metadata visitor- Throws:
Exception- if listing fails
-
write
Description copied from interface:I_CmsImageCacheWrites an image cache entry.- Specified by:
writein interfaceI_CmsImageCache- Parameters:
key- the image cache keycontent- the image cache content- Throws:
Exception- if writing fails- See Also:
-
writeRangeTo
Description copied from interface:I_CmsImageCacheWrites an image cache entry byte range to the output stream.- Specified by:
writeRangeToin interfaceI_CmsImageCache- Parameters:
key- the image cache keystart- the first byte to writelength- the number of bytes to writeout- the output stream- Throws:
Exception- if reading fails- See Also:
-
writeTo
Description copied from interface:I_CmsImageCacheWrites an image cache entry to the output stream.- Specified by:
writeToin interfaceI_CmsImageCache- Parameters:
key- the image cache keyout- the output stream- Throws:
Exception- if reading fails- See Also:
-
initClient
Initializes the S3 client.- Parameters:
s3Client- the S3 client- Throws:
Exception- if the configured bucket can not be accessed
-