DiskLruCache学习摘要

  • DiskLruCache构造函数

valueCount:valueCount the number of values per cache entry. Must be positive.比如okhttp中的缓存每一个url请求cache有四个文件,两个状态(DIRY,CLEAN),每个状态对应两个文件:一个0文件对应存储meta数据,一个文件存储body数据

 /**
   * Create a cache which will reside in {@code directory}. This cache is lazily initialized on
   * first access and will be created if it does not exist.
   *
   * @param directory a writable directory
   * @param valueCount the number of values per cache entry. Must be positive.
   * @param maxSize the maximum number of bytes this cache should use to store
   */
  public static DiskLruCache create(FileSystem fileSystem, File directory, int appVersion,
      int valueCount, long maxSize) {
    if (maxSize <= 0) {
      throw new IllegalArgumentException("maxSize <= 0");
    }
    if (valueCount <= 0) {
      throw new IllegalArgumentException("valueCount <= 0");
    }

    // Use a single background thread to evict entries.
    Executor executor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS,
        new LinkedBlockingQueue<Runnable>(), Util.threadFactory("OkHttp DiskLruCache", true));

    return new DiskLruCache(fileSystem, directory, appVersion, valueCount, maxSize, executor);
  }

参考资料1

猜你喜欢

转载自blog.csdn.net/shaoyangtangsong/article/details/87867908