code: def create_hub_cache_endpoint(
      hub_cache_watcher: HubCacheWatcher,
  ) -> Endpoint:
      async def hub_cache_endpoint(request: Request) -> Response:
          logging.info("/hub-cache")
  
          all = (
              get_request_parameter(
                  request, "all", default="false"
              ).lower()
              == "true"
          )
          # ^ the values that trigger the initialization are "true", "True" and any other case-insensitive variant
  
          uuid, event = hub_cache_watcher.subscribe()
          if all:
              init_task = hub_cache_watcher.run_initialization(uuid)
  
          async def event_generator() -> AsyncGenerator[
              ServerSentEvent, None
          ]:
              try:
                  while True:
                      new_value = await event.wait_value()
                      event.clear()
                      if new_value is not None:
                          logging.debug(
                              f"Sending new value: {new_value}"
                          )
                          yield ServerSentEvent(
                              data=json.dumps(
                                  dataclasses.asdict(new_value)
                              ),
                              event="message",
                          )
              finally:
                  hub_cache_watcher.unsubscribe(uuid)
                  if all:
                      await init_task
  
          return EventSourceResponse(
              error_handling(event_generator()),
              media_type="text/event-stream",
          )
  
      return hub_cache_endpoint
  
file_path: datasets-server/services/sse-api/src/sse_api/routes/hub_cache.py
imports: import dataclasses
  import json
  import logging
  from asyncio import CancelledError
  from collections.abc import AsyncGenerator, AsyncIterable
  from libapi.request import get_request_parameter
  from libapi.utils import Endpoint
  from sse_starlette import EventSourceResponse, ServerSentEvent
  from starlette.requests import Request
  from starlette.responses import Response
  from sse_api.watcher import HubCacheWatcher
label_desc: Use image node_id 1 for calling a global function with example usage: create_hub_cache_endpoint(hub_cache_watcher) and returns: hub_cache_endpoint, EventSourceResponse