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 aBinaryManager
that uses a cache for its files because fetching them is expensive.Initialization of the
BinaryManager
must 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 File
cachedir
FileCache
fileCache
protected FileStorage
fileStorage
-
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 void
close()
Closes the binary manager and releases all resources and temporary objects held by it.protected Binary
getBinary(InputStream in)
Creates a binary value from the given input stream.Binary
getBinary(String digest)
Returns aBinary
corresponding to the given digest.File
getFile(String digest)
Gets a file from cache or storage.void
initialize(String blobProviderId, Map<String,String> properties)
Initializes the binary manager.protected void
initializeCache(File dir, long maxSize, long maxCount, long minAge, FileStorage fileStorage)
Initialize the cache.void
initializeCache(String maxSizeStr, String maxCountStr, String minAgeStr, FileStorage fileStorage)
Initializes the cache.void
initializeCache(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:BinaryManager
Initializes the binary manager.- Specified by:
initialize
in interfaceBinaryManager
- Overrides:
initialize
in 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:BinaryManager
Closes 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:AbstractBinaryManager
Creates a binary value from the given input stream.- Specified by:
getBinary
in classAbstractBinaryManager
- Throws:
IOException
-
getBinary
public Binary getBinary(String digest)
Description copied from interface:BinaryManager
Returns aBinary
corresponding to the given digest.A
null
is returned if the digest could not be found.- Specified by:
getBinary
in interfaceBinaryManager
- Specified by:
getBinary
in 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
-
-