Class DefaultFilesCache

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, FilesCache, VfsComponent

    public class DefaultFilesCache
    extends AbstractFilesCache
    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.

    • Field Detail

      • filesystemCache

        private final java.util.concurrent.ConcurrentMap<FileSystem,​java.util.concurrent.ConcurrentMap<FileName,​FileObject>> filesystemCache
        The FileSystem cache. Keeps one Map for each FileSystem.
    • Constructor Detail

      • DefaultFilesCache

        public DefaultFilesCache()
    • Method Detail

      • putFile

        public void putFile​(FileObject file)
        Description copied from interface: FilesCache
        Adds a FileObject to the cache.
        Parameters:
        file - the file
      • putFileIfAbsent

        public boolean putFileIfAbsent​(FileObject file)
        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.
      • getFile

        public FileObject getFile​(FileSystem filesystem,
                                  FileName name)
        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
      • clear

        public void clear​(FileSystem filesystem)
        Description copied from interface: FilesCache
        Purges the entries corresponding to the FileSystem.
        Parameters:
        filesystem - The FileSystem.
      • getOrCreateFilesystemCache

        protected java.util.concurrent.ConcurrentMap<FileName,​FileObject> getOrCreateFilesystemCache​(FileSystem filesystem)
      • close

        public void close()
        Description copied from class: AbstractVfsComponent
        Closes the provider. This implementation does nothing.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface FilesCache
        Specified by:
        close in interface VfsComponent
        Overrides:
        close in class AbstractVfsComponent
      • removeFile

        public void removeFile​(FileSystem filesystem,
                               FileName name)
        Description copied from interface: FilesCache
        Removes a file from cache.
        Parameters:
        filesystem - file system
        name - file name