Package org.apache.commons.vfs2.cache
Class DefaultFilesCache
java.lang.Object
org.apache.commons.vfs2.provider.AbstractVfsComponent
org.apache.commons.vfs2.cache.AbstractFilesCache
org.apache.commons.vfs2.cache.DefaultFilesCache
- All Implemented Interfaces:
Closeable
,AutoCloseable
,FilesCache
,VfsComponent
A simple
FilesCache
implementation.
This implementation caches every file with no expire or limit. All files and file systems are hard reachable references. This implementation holds a list of file system specific ConcurrentHashMaps in the main cache map.
Cached FileObjects as well as FileSystems are only removed when
clear(FileSystem)
is called (i.e. on file system close). When the used
FileSystemManager
is closed, it will also close this cache (which frees all entries).
Despite its name, this is not the fallback implementation used by
DefaultFileSystemManager#init()
anymore.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear
(FileSystem filesystem) Purges the entries corresponding to the FileSystem.void
close()
Closes the provider.getFile
(FileSystem filesystem, FileName name) Retrieves a FileObject from the cache by name.protected ConcurrentMap<FileName,
FileObject> getOrCreateFilesystemCache
(FileSystem fileSystem) Gets or creates a Map.void
putFile
(FileObject file) Adds a FileObject to the cache.boolean
putFileIfAbsent
(FileObject file) Adds a FileObject to the cache if it isn't already present.void
removeFile
(FileSystem filesystem, FileName name) Removes a file from cache.Methods inherited from class org.apache.commons.vfs2.cache.AbstractFilesCache
touchFile
Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, init, setContext, setLogger
-
Constructor Details
-
DefaultFilesCache
public DefaultFilesCache()Constructs a new instance.
-
-
Method Details
-
clear
Description copied from interface:FilesCache
Purges the entries corresponding to the FileSystem.- Parameters:
filesystem
- The FileSystem.
-
close
Description copied from class:AbstractVfsComponent
Closes the provider. This implementation does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFilesCache
- Specified by:
close
in interfaceVfsComponent
- Overrides:
close
in classAbstractVfsComponent
-
getFile
Description copied from interface:FilesCache
Retrieves 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 Map.- Parameters:
fileSystem
- the key- Returns:
- an existing or new Map.
-
putFile
Description copied from interface:FilesCache
Adds a FileObject to the cache.- Parameters:
file
- the file
-
putFileIfAbsent
Description copied from interface:FilesCache
Adds 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:FilesCache
Removes a file from cache.- Parameters:
filesystem
- file systemname
- file name
-