public class LocalCache extends Object
CachingDataStore
. If cache
size exceeds limit, this cache goes in purge mode. In purge mode any
operation to cache is no-op. After purge cache size would be less than
cachePurgeResizeFactor * maximum size.Constructor and Description |
---|
LocalCache(String path,
String tmpPath,
long maxSizeInBytes,
double cachePurgeTrigFactor,
double cachePurgeResizeFactor,
AsyncUploadCache asyncUploadCache)
Build LRU cache of files located at 'path'.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the cache.
|
void |
delete(String fileName)
Delete file from cache.
|
File |
getFileIfStored(String fileName) |
Long |
getFileLength(String fileName)
Returns length of file if exists in cache else returns null.
|
InputStream |
getIfStored(String fileName)
Return the inputstream from from cache, or null if not in the cache.
|
File |
store(String fileName,
File src)
Store an item along with file in cache.
|
AsyncUploadCacheResult |
store(String fileName,
File src,
boolean tryForAsyncUpload)
This method add file to
LocalCache and tries that file can be
added to AsyncUploadCache . |
InputStream |
store(String fileName,
InputStream in)
Store an item in the cache and return the input stream.
|
public LocalCache(String path, String tmpPath, long maxSizeInBytes, double cachePurgeTrigFactor, double cachePurgeResizeFactor, AsyncUploadCache asyncUploadCache)
path
- file system pathtmpPath
- temporary directory used by cache.maxSizeInBytes
- maximum size of cache.cachePurgeTrigFactor
- factor which triggers cache to purge mode.
That is if current size exceed (cachePurgeTrigFactor * maxSizeInBytes), the
cache will go in auto-purge mode.cachePurgeResizeFactor
- after cache purge size of cache will be
just less (cachePurgeResizeFactor * maxSizeInBytes).asyncUploadCache
- AsyncUploadCache
public InputStream store(String fileName, InputStream in) throws IOException
TransientFileFactory.createTransientFile(String, String, File)
is
returned. Otherwise inputStream from cached file is returned. This method
doesn't close the incoming inputstream.fileName
- the key of cache.in
- InputStream
IOException
public File store(String fileName, File src)
File.length()
If file already exists in cache,
File.setLastModified(long)
is updated with current time.fileName
- the key of cache.src
- file to be added to cache.public AsyncUploadCacheResult store(String fileName, File src, boolean tryForAsyncUpload) throws IOException
LocalCache
and tries that file can be
added to AsyncUploadCache
. If file is added to
AsyncUploadCache
successfully, it sets
AsyncUploadCacheResult.setAsyncUpload(boolean)
to true.fileName
- name of the file.src
- source file.tryForAsyncUpload
- If true it tries to add fileName to
AsyncUploadCache
AsyncUploadCacheResult
. This method sets
AsyncUploadCacheResult.setAsyncUpload(boolean)
to true, if
fileName is added to AsyncUploadCache
successfully else
it sets AsyncUploadCacheResult.setAsyncUpload(boolean)
to
false. AsyncUploadCacheResult.getFile()
contains cached
file, if it is added to LocalCache
or original file.IOException
public InputStream getIfStored(String fileName) throws IOException
fileName
- name of file.IOException
public File getFileIfStored(String fileName) throws IOException
IOException
public void delete(String fileName)
fileName
- file name that need to be removed from cache.public Long getFileLength(String fileName)
fileName
- name of the file.public void close()
Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.