```python:inference/core/cache/air_gapped.py
import hashlib
import os
import re

from inference.core.env import MODEL_CACHE_DIR

# Pre-compile regex patterns to avoid recompilation overhead
_PATTERN_NON_ALPHANUM = re.compile(r"[^A-Za-z0-9_-]+")
_PATTERN_MULTIPLE_SEPARATORS = re.compile(r"[_-]{2,}")

def _slugify_model_id(model_id: str) -> str:
    """Reproduce the slug used by inference-models for cache directory names.

    Must stay in sync with
    ``inference_models.models.auto_loaders.core.slugify_model_id_to_os_safe_format``.
    """
    slug = _PATTERN_NON_ALPHANUM.sub("-", model_id)
    slug = _PATTERN_MULTIPLE_SEPARATORS.sub("-", slug)
    if not slug:
        slug = "special-char-only-model-id"
    if len(slug) > 48:
        slug = slug[:48]
    digest = hashlib.blake2s(model_id.encode("utf-8"), digest_size=4).hexdigest()
    return f"{slug}-{digest}"


def _is_model_cached(model_id: str) -> bool:
    """Check if *model_id* has cached artifacts in either cache layout.

    Layout 1 (traditional): ``MODEL_CACHE_DIR/{model_id}/`` with files inside.
    Layout 2 (inference-models): ``MODEL_CACHE_DIR/models-cache/{slug}/`` with
    sub-directories containing model files.
    """
    # Traditional layout
    traditional_path = os.path.join(MODEL_CACHE_DIR, model_id)
    try:
        with os.scandir(traditional_path) as entries:
            if next(entries, None) is not None:
                return True
    except (FileNotFoundError, NotADirectoryError):
        pass

    # inference-models layout

    # inference-models layout
    slug = _slugify_model_id(model_id)
    models_cache_path = os.path.join(MODEL_CACHE_DIR, "models-cache", slug)
    try:
        with os.scandir(models_cache_path) as entries:
            if next(entries, None) is not None:
                return True
    except (FileNotFoundError, NotADirectoryError):
        pass

    return False
```