code: def update_cache(base_dir, followlinks=False):
      mtimes = {}
      files_by_dir = {}
      dirs = _get_subdirs(base_dir, files_by_dir, followlinks)
      for d in dirs:
          os.stat(d)
          mtimes[d] = os.stat(d).st_mtime
      with DB.readwrite_cursor() as c:
          c.execute("SELECT path, mtime FROM directory")
          db_mtimes = dict(c)
          c.execute("SELECT uid FROM study")
          studies = [row[0] for row in c]
          c.execute("SELECT uid FROM series")
          series = [row[0] for row in c]
          c.execute("SELECT uid FROM storage_instance")
          storage_instances = [row[0] for row in c]
          for dir in sorted(mtimes.keys()):
              if dir in db_mtimes and mtimes[dir] <= db_mtimes[dir]:
                  continue
              logger.debug(f"updating {dir}")
              _update_dir(
                  c,
                  dir,
                  files_by_dir[dir],
                  studies,
                  series,
                  storage_instances,
              )
              if dir in db_mtimes:
                  query = (
                      "UPDATE directory SET mtime = ? WHERE path = ?"
                  )
                  c.execute(query, (mtimes[dir], dir))
              else:
                  query = "INSERT INTO directory (path, mtime) VALUES (?, ?)"
                  c.execute(query, (dir, mtimes[dir]))
  
imports: import contextlib
  import getpass
  import logging
  import os
  import sqlite3
  import tempfile
  import warnings
  from io import BytesIO
  from os.path import join
  import numpy
  from nibabel.optpkg import optional_package
  from .nifti1 import Nifti1Header
label_desc: Use image node_id 2 for calling a global function with example usage: update_cache(base_dir, followlinks) without return types