예제 #1
0
  public static synchronized void deleteExpired() {

    Date expiryDate;
    long freeSpace = getFreeUserSpace();
    if (freeSpace < Globals.DISK_FREE_THRESHOLD)
      expiryDate = new Date(new Date().getTime() - Globals.FILE_KEEP_IN_CACHE_DURATION_MS_MINIMAL);
    else expiryDate = new Date(new Date().getTime() - Globals.FILE_KEEP_IN_CACHE_DURATION_MS);

    Log.warn(
        "running Delete Expired job",
        "expiryDate=" + expiryDate.toString() + " , freeSpace=" + freeSpace);
    File folder = new File(Config.cachePath);
    for (final File file : folder.listFiles()) {
      if (file.isFile() && file.getName().endsWith(Globals.FILE_EXT_DATA)) {
        BasicFileAttributes attrs;
        try {
          attrs = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
          Date fileLastAccessTime = new Date(attrs.lastAccessTime().toMillis());
          if (fileLastAccessTime.before(expiryDate)) deleteDataAndHeaderFiles(file);
        } catch (Exception e) {
          Log.error("Cannot read file attributes", e.getCause() + " : " + e.getMessage());
          e.printStackTrace();
        }
      }
    }
  }