code: def _get_cached_revision_directory(
      model_id: str, revision: Optional[str]
  ) -> Optional[Path]:
      if revision is None:
          revision = "main"
  
      repo_cache = Path(HUGGINGFACE_HUB_CACHE) / Path(
          file_download.repo_folder_name(
              repo_id=model_id, repo_type="model"
          )
      )
  
      if not repo_cache.is_dir():
          # No cache for this model
          return None
  
      refs_dir = repo_cache / "refs"
      snapshots_dir = repo_cache / "snapshots"
  
      # Resolve refs (for instance to convert main to the associated commit sha)
      if refs_dir.is_dir():
          revision_file = refs_dir / revision
          if revision_file.exists():
              with revision_file.open() as f:
                  revision = f.read()
  
      # Check if revision folder exists
      if not snapshots_dir.exists():
          return None
      cached_shas = os.listdir(snapshots_dir)
      if revision not in cached_shas:
          # No cache for this revision and we won't try to return a random revision
          return None
  
      return snapshots_dir / revision
  
file_path: text-generation-inference/server/text_generation_server/utils/hub.py
imports: import time
  import os
  from datetime import timedelta
  from loguru import logger
  from pathlib import Path
  from typing import Optional, List
  from huggingface_hub import file_download, hf_api, HfApi, hf_hub_download
  from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
  from huggingface_hub.utils import LocalEntryNotFoundError, EntryNotFoundError, RevisionNotFoundError
label_desc: Use image node_id 4 for calling a global function with example usage: _get_cached_revision_directory(model_id, revision) and returns: unknown, None, None, None