Package org.miaixz.bus.core.cache.file
Class AbstractFileCache
java.lang.Object
org.miaixz.bus.core.cache.file.AbstractFileCache
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
LFUFileCache,LRUFileCache
文件缓存,以解决频繁读取文件引起的性能问题
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()voidclear()清空缓存intbyte[]getFileBytes(File file) 获得缓存过的文件bytesbyte[]getFileBytes(String path) 获得缓存过的文件bytesint初始化实现文件缓存的缓存对象intlongtimeout()
-
Field Details
-
capacity
protected final int capacity容量 -
maxFileSize
protected final int maxFileSize缓存的最大文件大小,文件大于此大小时将不被缓存 -
timeout
protected final long timeout默认超时时间,0表示无默认超时 -
cache
缓存实现 -
usedSize
protected int usedSize已使用缓存空间
-
-
Constructor Details
-
AbstractFileCache
public AbstractFileCache(int capacity, int maxFileSize, long timeout) 构造- Parameters:
capacity- 缓存容量maxFileSize- 文件最大大小timeout- 默认超时时间,0表示无默认超时
-
-
Method Details
-
capacity
public int capacity()- Returns:
- 缓存容量(byte数)
-
getUsedSize
public int getUsedSize()- Returns:
- 已使用空间大小(byte数)
-
maxFileSize
public int maxFileSize()- Returns:
- 允许被缓存文件的最大byte数
-
getCachedFilesCount
public int getCachedFilesCount()- Returns:
- 缓存的文件数
-
timeout
public long timeout()- Returns:
- 超时时间
-
clear
public void clear()清空缓存 -
getFileBytes
获得缓存过的文件bytes- Parameters:
path- 文件路径- Returns:
- 缓存过的文件bytes
- Throws:
InternalException- IO异常
-
getFileBytes
获得缓存过的文件bytes- Parameters:
file- 文件- Returns:
- 缓存过的文件bytes
- Throws:
InternalException- IO异常
-
initCache
初始化实现文件缓存的缓存对象- Returns:
Cache
-