Package org.nuxeo.ecm.core.blob.binary
Class CachingBinaryManager
- java.lang.Object
-
- org.nuxeo.ecm.core.blob.binary.AbstractBinaryManager
-
- org.nuxeo.ecm.core.blob.binary.CachingBinaryManager
-
- All Implemented Interfaces:
BinaryManager
- Direct Known Subclasses:
AbstractCloudBinaryManager
public abstract class CachingBinaryManager extends AbstractBinaryManager
Abstract class for aBinaryManagerthat uses a cache for its files because fetching them is expensive.Initialization of the
BinaryManagermust callinitializeCache(java.io.File, long, long, long, org.nuxeo.ecm.core.blob.binary.FileStorage)from theinitialize(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)method.- Since:
- 5.7
-
-
Field Summary
Fields Modifier and Type Field Description protected FilecachedirFileCachefileCacheprotected FileStoragefileStorage-
Fields inherited from class org.nuxeo.ecm.core.blob.binary.AbstractBinaryManager
blobProviderId, DEFAULT_DEPTH, DEFAULT_DIGEST, descriptor, digestPattern, DIGESTS_BY_LENGTH, garbageCollector, MAX_BUF_SIZE, MD5_DIGEST, MD5_DIGEST_LENGTH, MIN_BUF_SIZE, properties, SHA1_DIGEST, SHA1_DIGEST_LENGTH, SHA256_DIGEST, SHA256_DIGEST_LENGTH
-
Fields inherited from interface org.nuxeo.ecm.core.blob.binary.BinaryManager
PROP_KEY, PROP_PATH
-
-
Constructor Summary
Constructors Constructor Description CachingBinaryManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the binary manager and releases all resources and temporary objects held by it.protected BinarygetBinary(InputStream in)Creates a binary value from the given input stream.BinarygetBinary(String digest)Returns aBinarycorresponding to the given digest.FilegetFile(String digest)Gets a file from cache or storage.voidinitialize(String blobProviderId, Map<String,String> properties)Initializes the binary manager.protected voidinitializeCache(File dir, long maxSize, long maxCount, long minAge, FileStorage fileStorage)Initialize the cache.voidinitializeCache(String maxSizeStr, String maxCountStr, String minAgeStr, FileStorage fileStorage)Initializes the cache.voidinitializeCache(String maxSizeStr, FileStorage fileStorage)Initialize the cache.-
Methods inherited from class org.nuxeo.ecm.core.blob.binary.AbstractBinaryManager
computeDigestPattern, getBinary, getDefaultDigestAlgorithm, getDescriptor, getDigestAlgorithm, getGarbageCollector, isValidDigest, removeBinaries, setDescriptor, storeAndDigest, toHexString
-
-
-
-
Field Detail
-
cachedir
protected File cachedir
-
fileCache
public FileCache fileCache
-
fileStorage
protected FileStorage fileStorage
-
-
Method Detail
-
initialize
public void initialize(String blobProviderId, Map<String,String> properties) throws IOException
Description copied from interface:BinaryManagerInitializes the binary manager.- Specified by:
initializein interfaceBinaryManager- Overrides:
initializein classAbstractBinaryManager- Parameters:
blobProviderId- the blob provider id for this binary managerproperties- initialization properties- Throws:
IOException
-
initializeCache
protected void initializeCache(File dir, long maxSize, long maxCount, long minAge, FileStorage fileStorage)
Initialize the cache.- Parameters:
dir- the directory to use to store cached filesmaxSize- the maximum size of the cache (in bytes)maxCount- the maximum number of files in the cacheminAge- the minimum age of a file in the cache to be eligible for removal (in seconds)fileStorage- the file storage mechanism to use to store and fetch files- Since:
- 5.9.2
-
initializeCache
public void initializeCache(String maxSizeStr, FileStorage fileStorage) throws IOException
Initialize the cache.- Parameters:
maxSizeStr- the maximum size of the cache (as a String)fileStorage- the file storage mechanism to use to store and fetch files- Throws:
IOException- Since:
- 6.0
- See Also:
initializeCache(String, String, String, FileStorage)
-
initializeCache
public void initializeCache(String maxSizeStr, String maxCountStr, String minAgeStr, FileStorage fileStorage) throws IOException
Initializes the cache.- Parameters:
maxSizeStr- the maximum size of the cache (as a String)maxCountStr- the maximum number of files in the cacheminAgeStr- the minimum age of a file in the cache to be eligible for removal (in seconds)fileStorage- the file storage mechanism to use to store and fetch files- Throws:
IOException- Since:
- 7.10-HF03, 8.1
- See Also:
SizeUtils.parseSizeInBytes(String)
-
close
public void close()
Description copied from interface:BinaryManagerCloses the binary manager and releases all resources and temporary objects held by it.
-
getBinary
protected Binary getBinary(InputStream in) throws IOException
Description copied from class:AbstractBinaryManagerCreates a binary value from the given input stream.- Specified by:
getBinaryin classAbstractBinaryManager- Throws:
IOException
-
getBinary
public Binary getBinary(String digest)
Description copied from interface:BinaryManagerReturns aBinarycorresponding to the given digest.A
nullis returned if the digest could not be found.- Specified by:
getBinaryin interfaceBinaryManager- Specified by:
getBinaryin classAbstractBinaryManager- Parameters:
digest- the digest, ornull- Returns:
- the corresponding binary
-
getFile
public File getFile(String digest) throws IOException
Gets a file from cache or storage.Used by
LazyBinary.- Throws:
IOException
-
-