def get_cache_key(endpoint, identity, page, per_page, sort, route_arg=None):
    """Build a cache key for the endpoint."""
    if not identity:
        identity = "anonymous"

    cache_key = "{}_{}_{}_{}_{}".format(endpoint, identity, page, per_page, sort)
    if route_arg:
        cache_key = "{}_{}".format(cache_key, route_arg)

    return cache_key