Class AbstractFileCache

java.lang.Object
org.miaixz.bus.core.cache.file.AbstractFileCache
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
LFUFileCache, LRUFileCache

public abstract class AbstractFileCache extends Object implements Serializable
文件缓存,以解决频繁读取文件引起的性能问题
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Details

    • capacity

      protected final int capacity
      容量
    • maxFileSize

      protected final int maxFileSize
      缓存的最大文件大小,文件大于此大小时将不被缓存
    • timeout

      protected final long timeout
      默认超时时间,0表示无默认超时
    • cache

      protected final Cache<File,byte[]> 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

      public byte[] getFileBytes(String path) throws InternalException
      获得缓存过的文件bytes
      Parameters:
      path - 文件路径
      Returns:
      缓存过的文件bytes
      Throws:
      InternalException - IO异常
    • getFileBytes

      public byte[] getFileBytes(File file) throws InternalException
      获得缓存过的文件bytes
      Parameters:
      file - 文件
      Returns:
      缓存过的文件bytes
      Throws:
      InternalException - IO异常
    • initCache

      protected abstract Cache<File,byte[]> initCache()
      初始化实现文件缓存的缓存对象
      Returns:
      Cache