Package org.apache.commons.vfs2.cache
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.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance.LRUFilesCache(int lruSize) Constructs a new instance with the desired LRU size. -
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) Gets or creates a new Map.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 org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, init, setContext, setLogger
-
Constructor Details
-
LRUFilesCache
public LRUFilesCache()Constructs a new instance. Uses an LRU size of 100 per file system. -
LRUFilesCache
Constructs a new instance with the desired LRU size.- Parameters:
lruSize- the LRU size
-
-
Method Details
-
clear
Description copied from interface:FilesCachePurges the entries corresponding to the FileSystem.- Parameters:
filesystem- The FileSystem.
-
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
-
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
-
getOrCreateFilesystemCache
Gets or creates a new Map.- Parameters:
fileSystem- the key- Returns:
- an existing or new Map.
-
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.
-
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.
-