def METHOD_NAME(
    doc_info: DocInfo,
    current_user: "User",
    view_ctx: ViewContext,
    m: DocViewParams,
    nocache: bool,
) -> CacheResult:
    cache_key = get_doc_cache_key(doc_info, current_user, view_ctx, m)
    not_cached = CacheResult(key=cache_key, doc=None)
    if view_ctx.route not in allowed_cache_routes:
        return not_cached
    # Skip and clear cache if requested.
    if nocache:
        clear_doc_cache(doc_info, user=None)
        return not_cached
    try:
        cached: tuple[bytes, bytes, bytes, bytes] = rclient.lrange(cache_key, 0, -1)  # type: ignore
    except ResponseError:
        return not_cached
    if cached:
        try:
            head_b, content_b, override_b, hide_readmarks_b = cached
            head = head_b.decode()
            content = content_b.decode()
            override = override_b.decode() if override_b else None
            hide_readmarks = bool(int(hide_readmarks_b))
        except ValueError:
            # If for whatever reason the cache is corrupted, just ignore it.
            return not_cached
        return CacheResult(
            doc=DocRenderResult(
                head_html=head,
                content_html=content,
                allowed_to_cache=True,
                override_theme=override,
                hide_readmarks=hide_readmarks,
            ),
            key=cache_key,
        )
    return not_cached