Package org.apache.commons.vfs2.cache
Class LRUFilesCache
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractVfsComponent
-
- org.apache.commons.vfs2.cache.AbstractFilesCache
-
- org.apache.commons.vfs2.cache.LRUFilesCache
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,FilesCache
,VfsComponent
public class LRUFilesCache extends AbstractFilesCache
This implementation caches every file usingLRUMap
.The default constructor uses a LRU size of 100 per file system.
-
-
Constructor Summary
Constructors Constructor Description LRUFilesCache()
Constructs a new instance.LRUFilesCache(int lruSize)
Constructs a new instance with the desired LRU size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear(FileSystem filesystem)
Purges the entries corresponding to the FileSystem.void
close()
Closes the provider.FileObject
getFile(FileSystem filesystem, FileName name)
Retrieves a FileObject from the cache by name.protected java.util.Map<FileName,FileObject>
getOrCreateFilesystemCache(FileSystem fileSystem)
Gets or creates a new Map.void
putFile(FileObject file)
Adds a FileObject to the cache.boolean
putFileIfAbsent(FileObject file)
Adds a FileObject to the cache if it isn't already present.void
removeFile(FileSystem filesystem, FileName name)
Removes a file from cache.void
touchFile(FileObject file)
Default implementation is a NOOP.-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, init, setContext, setLogger
-
-
-
-
Constructor Detail
-
LRUFilesCache
public LRUFilesCache()
Constructs a new instance. Uses an LRU size of 100 per file system.
-
LRUFilesCache
public LRUFilesCache(int lruSize)
Constructs a new instance with the desired LRU size.- Parameters:
lruSize
- the LRU size
-
-
Method Detail
-
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceFilesCache
- Specified by:
close
in interfaceVfsComponent
- Overrides:
close
in classAbstractVfsComponent
-
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
-
getOrCreateFilesystemCache
protected java.util.Map<FileName,FileObject> getOrCreateFilesystemCache(FileSystem fileSystem)
Gets or creates a new Map.- Parameters:
fileSystem
- the key- Returns:
- an existing or new Map.
-
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.
-
removeFile
public void removeFile(FileSystem filesystem, FileName name)
Description copied from interface:FilesCache
Removes a file from cache.- Parameters:
filesystem
- file systemname
- file name
-
touchFile
public void touchFile(FileObject file)
Description copied from class:AbstractFilesCache
Default implementation is a NOOP.- Overrides:
touchFile
in classAbstractFilesCache
- Parameters:
file
- touch this file.
-
-