async def get_postcode(postcode_like: PostCodeLike) -> Optional[Postcode]:
    """
    Gets the postcode object for a given postcode string.
    Acts as a middleware between us and the API, caching results.
    :param postcode_like: The either a string postcode or PostCode object.
    :return: The PostCode object else None if the postcode does not exist..
    :raises CachingError: When the postcode is not in cache, and the API is unreachable.
    """
    if isinstance(postcode_like, Postcode):
        return postcode_like

    postcode_like = postcode_like.replace(" ", "").upper()

    try:
        postcode = Postcode.get(Postcode.postcode == postcode_like)
    except DoesNotExist:
        try:
            postcode = await fetch_postcode_from_string(postcode_like)
        except (ApiError, CircuitBreakerError):
            raise CachingError(f"Requested postcode is not cached, and can't be retrieved.")
        if postcode is not None:
            postcode.save()

    return postcode
async def get_postcode(postcode_like: PostCodeLike) -> Optional[Postcode]:
    """
    Gets the postcode object for a given postcode string.
    Acts as a middleware between us and the API, caching results.
    :param postcode_like: The either a string postcode or PostCode object.
    :return: The PostCode object else None if the postcode does not exist..
    :raises CachingError: When the postcode is not in cache, and the API is unreachable.
    """
    if isinstance(postcode_like, Postcode):
        return postcode_like

    postcode_like = postcode_like.replace(" ", "").upper()

    try:
        postcode = Postcode.get(Postcode.postcode == postcode_like)
    except DoesNotExist:
        try:
            postcode = await fetch_postcode_from_string(postcode_like)
        except (ApiError, CircuitBreakerError):
            raise CachingError(f"Requested postcode is not cached, and can't be retrieved.")
        if postcode is not None:
            postcode.save()

    return postcode
async def get_postcode ( postcode_like : PostCodeLike ) -> Optional [ Postcode ] : if isinstance ( postcode_like , Postcode ) : return postcode_like postcode_like = postcode_like . replace ( " " , "" ) . upper ( ) try : postcode = Postcode . get ( Postcode . postcode == postcode_like ) except DoesNotExist : try : postcode = await fetch_postcode_from_string ( postcode_like ) except ( ApiError , CircuitBreakerError ) : raise CachingError ( f"Requested postcode is not cached, and can't be retrieved." ) if postcode is not None : postcode . save ( ) return postcode
Gets the postcode object for a given postcode string.
    Acts as a middleware between us and the API, caching results.
    :param postcode_like: The either a string postcode or PostCode object.
    :return: The PostCode object else None if the postcode does not exist..
    :raises CachingError: When the postcode is not in cache, and the API is unreachable.
Gets the postcode object for a given postcode string . Acts as a middleware between us and the API caching results . : param postcode_like : The either a string postcode or PostCode object . : return : The PostCode object else None if the postcode does not exist .. : raises CachingError : When the postcode is not in cache and the API is unreachable .