Package org.miaixz.bus.http.cache
Class DiskLruCache
java.lang.Object
org.miaixz.bus.http.cache.DiskLruCache
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAccess to read and write files on a hierarchical data store.final classEdits the values for an entry.final class快照信息 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this cache.static DiskLruCachecreate(DiskLruCache.DiskFile diskFile, File directory, int appVersion, int valueCount, long maxSize) 创建一个驻留在directory中的缓存。voiddelete()Closes the cache and deletes all of its stored values.返回名为key的条目的编辑器,如果另一个编辑正在进行,则返回nullvoidevictAll()Deletes all stored values from the cache.voidflush()Force buffered operations to the filesystem.返回名为key的条目的快照,如果条目不存在,则返回null, 否则当前无法读取。Returns the directory where this cache stores its data.longReturns the maximum number of bytes that this cache should use to store its data.voidbooleanisClosed()Returns true if this cache has been closed.booleanDrops the entry forkeyif it exists and can be removed.voidsetMaxSize(long maxSize) Changes the maximum number of bytes the cache can store and queues a job to trim the existing store, if necessary.longsize()Returns the number of bytes currently being used to store the values in this cache.返回缓存当前项的迭代器。
-
Method Details
-
create
public static DiskLruCache create(DiskLruCache.DiskFile diskFile, File directory, int appVersion, int valueCount, long maxSize) 创建一个驻留在directory中的缓存。此缓存在第一次访问时惰性初始化,如果它不存在,将创建它.- Parameters:
diskFile- 文件系统directory- 一个可写目录appVersion- 版本信息valueCount- 每个缓存条目的值数目.maxSize- 此缓存应用于存储的最大字节数- Returns:
- the disk cache
-
initialize
- Throws:
IOException
-
get
返回名为key的条目的快照,如果条目不存在,则返回null, 否则当前无法读取。如果返回一个值,它将被移动到LRU队列的头部- Parameters:
key- 缓存key- Returns:
- the 快照信息
- Throws:
IOException- 异常
-
edit
返回名为key的条目的编辑器,如果另一个编辑正在进行,则返回null- Parameters:
key- 文件key- Returns:
- 编辑器
- Throws:
IOException- 异常
-
getDirectory
Returns the directory where this cache stores its data. -
getMaxSize
public long getMaxSize()Returns the maximum number of bytes that this cache should use to store its data. -
setMaxSize
public void setMaxSize(long maxSize) Changes the maximum number of bytes the cache can store and queues a job to trim the existing store, if necessary. -
size
Returns the number of bytes currently being used to store the values in this cache. This may be greater than the max size if a background deletion is pending.- Throws:
IOException
-
remove
Drops the entry forkeyif it exists and can be removed. If the entry forkeyis currently being edited, that edit will complete normally but its value will not be stored.- Returns:
- true if an entry was removed.
- Throws:
IOException
-
isClosed
public boolean isClosed()Returns true if this cache has been closed. -
flush
Force buffered operations to the filesystem.- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
close
Closes this cache. Stored values will remain on the filesystem.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
delete
Closes the cache and deletes all of its stored values. This will delete all files in the cache directory including files that weren't created by the cache.- Throws:
IOException
-
evictAll
Deletes all stored values from the cache. In-flight edits will complete normally but their values will not be stored.- Throws:
IOException
-
snapshots
返回缓存当前项的迭代器。这个迭代器不会抛出ConcurrentModificationException, 调用者必须DiskLruCache.Snapshot.close()每个由Iterator.next()返回的快照 如果做不到这一点,就会泄漏打开的文件,返回的迭代器支持Iterator.remove().- Returns:
- 返回迭代器
- Throws:
IOException- 异常
-