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:
java.io.Closeable,java.lang.AutoCloseable,FilesCache,VfsComponent
public class DefaultFilesCache extends AbstractFilesCache
A simpleFilesCacheimplementation.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 usedFileSystemManageris 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 Constructor Description DefaultFilesCache()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(FileSystem filesystem)Purges the entries corresponding to the FileSystem.voidclose()Closes the provider.FileObjectgetFile(FileSystem filesystem, FileName name)Retrieves a FileObject from the cache by name.protected java.util.concurrent.ConcurrentMap<FileName,FileObject>getOrCreateFilesystemCache(FileSystem fileSystem)Gets or creates a 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.-
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 Detail
-
DefaultFilesCache
public DefaultFilesCache()
Constructs a new instance.
-
-
Method Detail
-
clear
public void clear(FileSystem filesystem)
Description copied from interface:FilesCachePurges the entries corresponding to the FileSystem.- Parameters:
filesystem- The FileSystem.
-
close
public void close()
Description copied from class:AbstractVfsComponentCloses the provider. This implementation does nothing.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceFilesCache- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
getFile
public FileObject getFile(FileSystem filesystem, FileName name)
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
protected java.util.concurrent.ConcurrentMap<FileName,FileObject> getOrCreateFilesystemCache(FileSystem fileSystem)
Gets or creates a Map.- Parameters:
fileSystem- the key- Returns:
- an existing or new Map.
-
putFile
public void putFile(FileObject file)
Description copied from interface:FilesCacheAdds a FileObject to the cache.- Parameters:
file- the file
-
putFileIfAbsent
public boolean putFileIfAbsent(FileObject file)
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
public void removeFile(FileSystem filesystem, FileName name)
Description copied from interface:FilesCacheRemoves a file from cache.- Parameters:
filesystem- file systemname- file name
-
-