Class LRUFilesCache
java.lang.Object
org.apache.commons.vfs2.provider.AbstractVfsComponent
org.apache.commons.vfs2.cache.AbstractFilesCache
org.apache.commons.vfs2.cache.LRUFilesCache
- All Implemented Interfaces:
Closeable, AutoCloseable, FilesCache, VfsComponent
This implementation caches every file using
LRUMap.
The default constructor uses a LRU size of 100 per file system.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe default LRU sizeprivate final ConcurrentMap<FileSystem, Map<FileName, FileObject>> The FileSystem cacheprivate static final org.apache.commons.logging.LogThe logger to use.private final intThe size of the cacheprivate final Lockprivate final ReadWriteLockprivate final Lock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(FileSystem filesystem) Purges the entries corresponding to the FileSystem.voidclose()Closes the provider.getFile(FileSystem filesystem, FileName name) Retrieves a FileObject from the cache by name.protected Map<FileName, FileObject> getOrCreateFilesystemCache(FileSystem filesystem) voidputFile(FileObject file) Adds a FileObject to the cache.booleanputFileIfAbsent(FileObject file) Adds a FileObject to the cache if it isn't already present.voidremoveFile(FileSystem filesystem, FileName name) Removes a file from cache.voidtouchFile(FileObject file) Default implementation is a NOOP.Methods inherited from class AbstractVfsComponent
getContext, getLogger, init, setContext, setLogger
-
Field Details
-
DEFAULT_LRU_SIZE
private static final int DEFAULT_LRU_SIZEThe default LRU size- See Also:
-
log
private static final org.apache.commons.logging.Log logThe logger to use. -
filesystemCache
The FileSystem cache -
lruSize
private final int lruSizeThe size of the cache -
rwLock
-
readLock
-
writeLock
-
-
Constructor Details
-
LRUFilesCache
public LRUFilesCache()Default constructor. Uses a LRU size of 100 per file system. -
LRUFilesCache
public LRUFilesCache(int lruSize) Set the desired LRU size.- Parameters:
lruSize- the LRU size
-
-
Method Details
-
putFile
Description copied from interface:FilesCacheAdds a FileObject to the cache.- Parameters:
file- the file
-
putFileIfAbsent
Description copied from interface:FilesCacheAdds a FileObject to the cache if it isn't already present.- Parameters:
file- the file- Returns:
- true if the file was stored, false otherwise.
-
getFile
Description copied from interface:FilesCacheRetrieves a FileObject from the cache by name.- Parameters:
filesystem- The FileSystem.name- the name- Returns:
- the file object or null if file is not cached
-
clear
Description copied from interface:FilesCachePurges the entries corresponding to the FileSystem.- Parameters:
filesystem- The FileSystem.
-
getOrCreateFilesystemCache
-
close
public void close()Description copied from class:AbstractVfsComponentCloses the provider. This implementation does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceFilesCache- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
removeFile
Description copied from interface:FilesCacheRemoves a file from cache.- Parameters:
filesystem- file systemname- file name
-
touchFile
Description copied from class:AbstractFilesCacheDefault implementation is a NOOP.- Overrides:
touchFilein classAbstractFilesCache- Parameters:
file- touch this file.
-