docstr: Clean up the cache, removing the least recently used files first.
  
  Args:
      target_size: The target size of the cache in bytes. If the cache is larger
          than this, we will remove the least recently used files until the cache
          is smaller than this size.
      remove_temp: Whether to remove temporary files. Temporary files are files
          that are currently being written to the cache. If remove_temp is True,
          all temp files will be removed, regardless of the target_size or
          target_fraction.
      target_fraction: The target fraction of the cache to reclaim. If the cache
          is larger than this, we will remove the least recently used files until
          the cache is smaller than this fraction of its current size. It is an
          error to specify both target_size and target_fraction.
  
  Returns:
      The number of bytes reclaimed.
docstr_tok: ["Clean","up","the","cache",",","removing","the","least","recently","used","files","first",".","Args",":","target_size",":","The","target","size","of","the","cache","in","bytes",".","If","the","cache","is","larger","than","this",",","we","will","remove","the","least","recently","used","files","until","the","cache","is","smaller","than","this","size",".","remove_temp",":","Whether","to","remove","temporary","files",".","Temporary","files","are","files","that","are","currently","being","written","to","the","cache",".","If","remove_temp","is","True",",","all","temp","files","will","be","removed",",","regardless","of","the","target_size","or","target_fraction",".","target_fraction",":","The","target","fraction","of","the","cache","to","reclaim",".","If","the","cache","is","larger","than","this",",","we","will","remove","the","least","recently","used","files","until","the","cache","is","smaller","than","this","fraction","of","its","current","size",".","It","is","an","error","to","specify","both","target_size","and","target_fraction",".","Returns",":","The","number","of","bytes","reclaimed","."]
code: def cleanup(
      self,
      target_size: Optional[int] = None,
      remove_temp: bool = False,
      target_fraction: Optional[float] = None,
  ) -> int:
      """Clean up the cache, removing the least recently used files first.
  
      Args:
          target_size: The target size of the cache in bytes. If the cache is larger
              than this, we will remove the least recently used files until the cache
              is smaller than this size.
          remove_temp: Whether to remove temporary files. Temporary files are files
              that are currently being written to the cache. If remove_temp is True,
              all temp files will be removed, regardless of the target_size or
              target_fraction.
          target_fraction: The target fraction of the cache to reclaim. If the cache
              is larger than this, we will remove the least recently used files until
              the cache is smaller than this fraction of its current size. It is an
              error to specify both target_size and target_fraction.
  
      Returns:
          The number of bytes reclaimed.
      """
      if target_size is None and target_fraction is None:
          # Default to clearing the entire cache.
          target_size = 0
      if target_size is not None and target_fraction is not None:
          raise ValueError(
              "Cannot specify both target_size and target_fraction"
          )
      if target_size and target_size < 0:
          raise ValueError("target_size must be non-negative")
      if target_fraction and (
          target_fraction < 0 or target_fraction > 1
      ):
          raise ValueError("target_fraction must be between 0 and 1")
  
      bytes_reclaimed = 0
      total_size = 0
      temp_size = 0
  
      # Remove all temporary files if requested. Otherwise sum their size.
      for entry in files_in(self._temp_dir):
          size = entry.stat().st_size
          total_size += size
          if remove_temp:
              try:
                  os.remove(entry.path)
                  bytes_reclaimed += size
              except OSError:
                  pass
          else:
              temp_size += size
      if temp_size:
          wandb.termwarn(
              f"Cache contains {util.to_human_size(temp_size)} of temporary files. "
              "Run `wandb artifact cleanup --remove-temp` to remove them."
          )
  
      entries = []
      for file_entry in files_in(self._obj_dir):
          total_size += file_entry.stat().st_size
          entries.append(file_entry)
  
      if target_fraction is not None:
          target_size = int(total_size * target_fraction)
      assert target_size is not None
  
      for entry in sorted(entries, key=lambda x: x.stat().st_atime):
          if total_size <= target_size:
              return bytes_reclaimed
          try:
              os.remove(entry.path)
          except OSError:
              pass
          total_size -= entry.stat().st_size
          bytes_reclaimed += entry.stat().st_size
  
      if total_size > target_size:
          wandb.termerror(
              f"Failed to reclaim enough space in {self._cache_dir}. Try running"
              " `wandb artifact cleanup --remove-temp` to remove temporary files."
          )
  
      return bytes_reclaimed
  
imports: import contextlib
  import errno
  import hashlib
  import os
  import shutil
  import subprocess
  import sys
  from pathlib import Path
  from tempfile import NamedTemporaryFile
  from typing import IO, TYPE_CHECKING, ContextManager, Generator, Optional, Tuple
  import wandb
  from wandb import env, util
  from wandb.errors import term
  from wandb.sdk.lib.filesystem import files_in
  from wandb.sdk.lib.hashutil import B64MD5, ETag, b64_to_hex_id
  from wandb.sdk.lib.paths import FilePathStr, StrPath, URIStr
label_desc: Use image node_id 5 for calling the ArtifactFileCache obj's underlying member method code with example usage: obj.cleanup(target_size, remove_temp, target_fraction) and returns: bytes_reclaimed, bytes_reclaimed