Class Cache

java.lang.Object
org.miaixz.bus.http.cache.Cache
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class Cache extends Object implements Closeable, Flushable
缓存HTTP和HTTPS对文件系统的响应,以便可以重用它们,从而节省时间和带宽.
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

  • Constructor Details

    • Cache

      public Cache(File directory, long maxSize)
      directory中创建最多maxSize字节的缓存
      Parameters:
      directory - 目录
      maxSize - 缓存的最大大小(以字节为单位)
    • Cache

      public Cache(File directory, long maxSize, DiskLruCache.DiskFile diskFile)
  • Method Details

    • key

      public static String key(UnoUrl url)
    • initialize

      public void initialize() throws IOException
      始化缓存。这将包括从存储器中读取日志文件并构建必要的内存缓存信息 注意,如果应用程序选择不调用此方法来初始化缓存。默认情况下,将在第一次使用缓存时执行延迟初始化
      Throws:
      IOException - 初始化异常
    • delete

      public void delete() throws IOException
      关闭缓存并删除其所有存储值。这将删除缓存目录中的所有文件,包括没有由缓存创建的文件
      Throws:
      IOException - 删除异常
    • evictAll

      public void evictAll() throws IOException
      删除缓存中存储的所有值。缓存中的写操作将正常完成,但不会存储相应的响应
      Throws:
      IOException - 清除异常
    • urls

      public Iterator<String> urls() throws IOException
      在此缓存中的url上返回一个迭代器,该迭代器支持Iterator.remove()。 从迭代器中删除URL将从缓存中删除相应的响应。使用此来清除选定的响应
      Returns:
      迭代器
      Throws:
      IOException - 异常
    • writeAbortCount

      public int writeAbortCount()
    • writeSuccessCount

      public int writeSuccessCount()
    • size

      public long size() throws IOException
      Throws:
      IOException
    • maxSize

      public long maxSize()
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • directory

      public File directory()
    • isClosed

      public boolean isClosed()
    • networkCount

      public int networkCount()
    • hitCount

      public int hitCount()
    • requestCount

      public int requestCount()