Class LRUFilesCache

All Implemented Interfaces:
Closeable, AutoCloseable, FilesCache, VfsComponent

public class LRUFilesCache extends AbstractFilesCache
This implementation caches every file using LRUMap.

The default constructor uses a LRU size of 100 per file system.

  • Field Details

    • DEFAULT_LRU_SIZE

      private static final int DEFAULT_LRU_SIZE
      The default LRU size
      See Also:
    • log

      private static final org.apache.commons.logging.Log log
      The logger to use.
    • filesystemCache

      private final ConcurrentMap<FileSystem,Map<FileName,FileObject>> filesystemCache
      The FileSystem cache
    • lruSize

      private final int lruSize
      The size of the cache
    • rwLock

      private final ReadWriteLock rwLock
    • readLock

      private final Lock readLock
    • writeLock

      private final Lock writeLock
  • Constructor Details

    • LRUFilesCache

      public LRUFilesCache()
      Default constructor. Uses a LRU size of 100 per file system.
    • LRUFilesCache

      public LRUFilesCache(int lruSize)
      Set the desired LRU size.
      Parameters:
      lruSize - the LRU size
  • Method Details

    • 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 Map<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 AutoCloseable
      Specified by:
      close in interface 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
    • touchFile

      public void touchFile(FileObject file)
      Description copied from class: AbstractFilesCache
      Default implementation is a NOOP.
      Overrides:
      touchFile in class AbstractFilesCache
      Parameters:
      file - touch this file.