public abstract class CachingBinaryManager extends AbstractBinaryManager
BinaryManager
that uses a cache for its files because fetching them is expensive.
Initialization of the BinaryManager
must call initializeCache(java.io.File, long, long, long, org.nuxeo.ecm.core.blob.binary.FileStorage)
from the initialize(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)
method.
Modifier and Type | Field and Description |
---|---|
protected File |
cachedir |
FileCache |
fileCache |
protected FileStorage |
fileStorage |
blobProviderId, DEFAULT_DEPTH, DEFAULT_DIGEST, descriptor, DIGESTS_BY_LENGTH, garbageCollector, MAX_BUF_SIZE, MD5_DIGEST, MD5_DIGEST_LENGTH, MIN_BUF_SIZE, SHA1_DIGEST, SHA1_DIGEST_LENGTH, SHA256_DIGEST, SHA256_DIGEST_LENGTH
PROP_KEY, PROP_PATH
Constructor and Description |
---|
CachingBinaryManager() |
Modifier and Type | Method and 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 a
Binary 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,
FileStorage fileStorage)
Initialize the cache.
|
void |
initializeCache(String maxSizeStr,
String maxCountStr,
String minAgeStr,
FileStorage fileStorage)
Initializes the cache.
|
getBinary, getDefaultDigestAlgorithm, getDescriptor, getDigestAlgorithm, getGarbageCollector, removeBinaries, storeAndDigest, toHexString
protected FileStorage fileStorage
public CachingBinaryManager()
public void initialize(String blobProviderId, Map<String,String> properties) throws IOException
BinaryManager
initialize
in interface BinaryManager
initialize
in class AbstractBinaryManager
blobProviderId
- the blob provider id for this binary managerproperties
- initialization propertiesIOException
protected void initializeCache(File dir, long maxSize, long maxCount, long minAge, FileStorage fileStorage)
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 filespublic void initializeCache(String maxSizeStr, FileStorage fileStorage) throws IOException
maxSizeStr
- the maximum size of the cache (as a String)fileStorage
- the file storage mechanism to use to store and fetch filesIOException
initializeCache(String, String, String, FileStorage)
public void initializeCache(String maxSizeStr, String maxCountStr, String minAgeStr, FileStorage fileStorage) throws IOException
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 filesIOException
SizeUtils.parseSizeInBytes(String)
public void close()
BinaryManager
protected Binary getBinary(InputStream in) throws IOException
AbstractBinaryManager
getBinary
in class AbstractBinaryManager
IOException
public Binary getBinary(String digest)
BinaryManager
Binary
corresponding to the given digest.
A null
is returned if the digest could not be found.
getBinary
in interface BinaryManager
getBinary
in class AbstractBinaryManager
digest
- the digest, or null
public File getFile(String digest) throws IOException
Used by LazyBinary
.
IOException
Copyright © 2017 Nuxeo. All rights reserved.