code: private static int cleanImageCache(long maxAge, File directory) {
  
          int count = 0;
          if (directory.canRead() && directory.isDirectory()) {
              File[] files = directory.listFiles();
              for (int i = 0; i < files.length; i++) {
                  File f = files[i];
                  if (f.isDirectory()) {
                      count += cleanImageCache(maxAge, f);
                  }
                  if (f.canWrite()) {
                      if (f.lastModified() < maxAge) {
                          try {
                              f.delete();
                              count++;
                          } catch (Exception e) {
                              LOG.error(
                                  Messages.get().getBundle().key(
                                      Messages.LOG_IMAGE_CACHE_UNABLE_TO_DELETE_1,
                                      f.getAbsolutePath()));
                          }
                      }
                  }
              }
              if (directory.listFiles().length <= 0) {
                  try {
                      directory.delete();
                      count++;
                  } catch (Exception e) {
                      LOG.error(
                          Messages.get().getBundle().key(
                              Messages.LOG_IMAGE_CACHE_UNABLE_TO_DELETE_1,
                              directory.getAbsolutePath()));
                  }
              }
          }
          return count;
      }
docs: Removes all expired image cache entries from the given RFS directory, including recursion to subdirectories.<p>
  
  @param maxAge the maximum age of the image cache files
  @param directory the directory to remove the cache files in
  
  @return the total number of deleted resources