Class SoftRefFilesCache
java.lang.Object
org.apache.commons.vfs2.provider.AbstractVfsComponent
org.apache.commons.vfs2.cache.AbstractFilesCache
org.apache.commons.vfs2.cache.SoftRefFilesCache
- All Implemented Interfaces:
Closeable, AutoCloseable, FilesCache, VfsComponent
- Direct Known Subclasses:
WeakRefFilesCache
This implementation caches every file as long as it is strongly reachable by the JVM. As soon as the JVM needs
memory - every softly reachable file will be discarded.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classThis thread will listen on the ReferenceQueue and remove the entry in the file cache as soon as the JVM removes the reference. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<FileSystem, Map<FileName, Reference<FileObject>>> private static final org.apache.commons.logging.Logprivate final ReferenceQueue<FileObject> private final Map<Reference<FileObject>, FileSystemAndNameKey> private SoftRefFilesCache.ReleaseThread -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(FileSystem fileSystem) Purges the entries corresponding to the FileSystem.voidclose()Closes the provider.private voidclose(FileSystem fileSystem) protected Reference<FileObject> createReference(FileObject file, ReferenceQueue<FileObject> refqueue) private voidgetFile(FileSystem fileSystem, FileName fileName) Retrieves a FileObject from the cache by name.protected Map<FileName, Reference<FileObject>> getOrCreateFilesystemCache(FileSystem fileSystem) private StringgetSafeName(FileName fileName) private StringgetSafeName(FileObject fileObject) voidputFile(FileObject fileObject) Adds a FileObject to the cache.booleanputFileIfAbsent(FileObject fileObject) Adds a FileObject to the cache if it isn't already present.private voidremoveFile(Reference<?> ref) private booleanvoidremoveFile(FileSystem fileSystem, FileName fileName) Removes a file from cache.private voidtoString()Methods inherited from class AbstractFilesCache
touchFileMethods inherited from class AbstractVfsComponent
getContext, getLogger, init, setContext, setLogger
-
Field Details
-
log
private static final org.apache.commons.logging.Log log -
fileSystemCache
-
refReverseMap
-
refQueue
-
releaseThread
-
-
Constructor Details
-
SoftRefFilesCache
public SoftRefFilesCache()Constructs a new instance.
-
-
Method Details
-
clear
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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceFilesCache- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
close
- Parameters:
fileSystem- The file system to close.
-
createReference
protected Reference<FileObject> createReference(FileObject file, ReferenceQueue<FileObject> refqueue) -
endThread
private void endThread() -
getFile
Description copied from interface:FilesCacheRetrieves a FileObject from the cache by name.- Parameters:
fileSystem- The FileSystem.fileName- the name- Returns:
- the file object or null if file is not cached
-
getOrCreateFilesystemCache
-
getSafeName
-
getSafeName
-
putFile
Description copied from interface:FilesCacheAdds a FileObject to the cache.- Parameters:
fileObject- the file
-
putFileIfAbsent
Description copied from interface:FilesCacheAdds a FileObject to the cache if it isn't already present.- Parameters:
fileObject- the file- Returns:
- true if the file was stored, false otherwise.
-
removeFile
Description copied from interface:FilesCacheRemoves a file from cache.- Parameters:
fileSystem- file systemfileName- file name
-
removeFile
-
removeFile
-
startThread
private void startThread() -
toString
-