```python:inference/core/roboflow_api.py
import hashlib
import json
import os
from functools import lru_cache
from inference.core.entities.types import WorkspaceID
from inference.core.env import MODEL_CACHE_DIR, SINGLE_TENANT_WORKFLOW_CACHE
from inference.core.utils.file_system import sanitize_path_segment
from typing import Optional

_WORKFLOW_CACHE_PREFIX = os.path.abspath(os.path.join(MODEL_CACHE_DIR, "workflow"))
_cached_sanitize_path_segment = lru_cache(maxsize=8192)(sanitize_path_segment)

@lru_cache(maxsize=4096)
def _cached_fingerprint(cache_seed: str) -> str:
    return hashlib.sha256(cache_seed.encode("utf-8"), usedforsecurity=False).hexdigest()


@lru_cache(maxsize=16384)
def get_workflow_cache_file(
    workspace_id: WorkspaceID,
    workflow_id: str,
    api_key: Optional[str],
    workflow_version_id: Optional[str] = None,
) -> str:
    sanitized_workspace_id = _cached_sanitize_path_segment(workspace_id)
    sanitized_workflow_id = _cached_sanitize_path_segment(workflow_id)
    if SINGLE_TENANT_WORKFLOW_CACHE:
        version_suffix = (
            f"_v{_cached_sanitize_path_segment(workflow_version_id)}"
            if workflow_version_id
            else ""
        )
        filename = f"{sanitized_workflow_id}{version_suffix}.json"
    else:
        cache_seed = f"{workspace_id}:{api_key or ''}"
        cache_fingerprint = _cached_fingerprint(cache_seed)
        filename = f"{sanitized_workflow_id}_{cache_fingerprint}.json"
    prefix = _WORKFLOW_CACHE_PREFIX
    result = os.path.abspath(
        os.path.join(
            prefix,
            sanitized_workspace_id,
            filename,
        )
    )
    if not result.startswith(prefix):
        raise ValueError(
            "Detected attempt to save workflow definition in insecure location"
        )
    return result


def delete_cached_workflow_response_if_exists(
    workspace_id: WorkspaceID,
    workflow_id: str,
    api_key: Optional[str],
    workflow_version_id: Optional[str] = None,
) -> None:
    workflow_cache_file = get_workflow_cache_file(
        workspace_id=workspace_id,
        workflow_id=workflow_id,
        api_key=api_key,
        workflow_version_id=workflow_version_id,
    )
    if os.path.exists(workflow_cache_file):
        os.remove(workflow_cache_file)


def load_cached_workflow_response(
    workspace_id: WorkspaceID,
    workflow_id: str,
    api_key: Optional[str],
    workflow_version_id: Optional[str] = None,
) -> Optional[dict]:
    workflow_cache_file = get_workflow_cache_file(
        workspace_id=workspace_id,
        workflow_id=workflow_id,
        api_key=api_key,
        workflow_version_id=workflow_version_id,
    )
    if not os.path.exists(workflow_cache_file):
        return None
    try:
        with open(workflow_cache_file, "r") as f:
            return json.load(f)
    except Exception:
        delete_cached_workflow_response_if_exists(
            workspace_id=workspace_id,
            workflow_id=workflow_id,
            api_key=api_key,
            workflow_version_id=workflow_version_id,
        )
```