Class SoftRefFilesCache

All Implemented Interfaces:
Closeable, AutoCloseable, FilesCache, VfsComponent
Direct Known Subclasses:
WeakRefFilesCache

public class SoftRefFilesCache extends AbstractFilesCache
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:
  • Field Details

  • Constructor Details

    • SoftRefFilesCache

      public SoftRefFilesCache()
      Constructs a new instance.
  • Method Details

    • clear

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

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

      private void close(FileSystem fileSystem)
      Parameters:
      fileSystem - The file system to close.
    • createReference

      protected Reference<FileObject> createReference(FileObject file, ReferenceQueue<FileObject> referenceQueue)
      Constructs a new Reference.
      Parameters:
      file - a file object.
      referenceQueue - a ReferenceQueue.
      Returns:
      a new Reference on the given input.
    • endThread

      private void endThread()
    • getFile

      public FileObject getFile(FileSystem fileSystem, FileName fileName)
      Description copied from interface: FilesCache
      Retrieves 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

      protected Map<FileName,Reference<FileObject>> getOrCreateFilesystemCache(FileSystem fileSystem)
      Gets or creates a new Map.
      Parameters:
      fileSystem - the key.
      Returns:
      an existing or new Map.
    • getSafeName

      private String getSafeName(FileName fileName)
    • getSafeName

      private String getSafeName(FileObject fileObject)
    • putFile

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

      public boolean putFileIfAbsent(FileObject fileObject)
      Description copied from interface: FilesCache
      Adds 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

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

      private boolean removeFile(FileSystemAndNameKey key)
    • removeFile

      private void removeFile(Reference<?> ref)
    • startThread

      private void startThread()
    • toString

      public String toString()
      Overrides:
      toString in class Object