/**
   * 查找缓存文件
   *
   * @param key
   * @param dir
   * @return
   * @throws com.log4ic.compressor.cache.exception.CacheException
   */
  public static CacheFile lookupCacheFile(String key, String dir) throws CacheException {
    Compressor.FileType[] types = Compressor.FileType.values();

    for (Compressor.FileType type : types) {
      CacheFile file = findCacheFile(key, type, dir);
      if (file.exists()) {
        return file;
      }
    }

    return null;
  }
  /**
   * 将缓存写入文件,如果文件存并且未过期在则直接返回该文件
   *
   * @param key
   * @param content
   * @param fileType
   * @param cacheDir
   * @param createDate
   * @return
   * @throws CacheException
   */
  public static CacheFile writeContent(
      String key, String content, Compressor.FileType fileType, String cacheDir, long createDate)
      throws CacheException {
    CacheFile file = findCacheFile(key, fileType, cacheDir);

    if (!file.getFile().exists() || file.getFile().lastModified() + 1000 < createDate) {
      logger.debug("尝试写入缓存文件....");
      File f = FileUtils.writeFile(content, file.getPath());
      logger.debug("写入缓存文件完毕!");
      return new SimpleCacheFile(f, fileType);
    }

    return file;
  }