Class LRUFilesCache

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.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 Detail

      • DEFAULT_LRU_SIZE

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

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

        private final java.util.concurrent.ConcurrentMap<FileSystem,​java.util.Map<FileName,​FileObject>> filesystemCache
        The FileSystem cache
      • lruSize

        private final int lruSize
        The size of the cache
      • rwLock

        private final java.util.concurrent.locks.ReadWriteLock rwLock
      • readLock

        private final java.util.concurrent.locks.Lock readLock
      • writeLock

        private final java.util.concurrent.locks.Lock writeLock
    • Constructor Detail

      • 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 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.
      • 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