'Google API has limits, so we can\'t generate new Polyline at every tick...'

@staticmethod
def cached_polyline(origin, destination, google_map_api_key=None):

    if (PolylineObjectHandler._cache and (PolylineObjectHandler._cache.get_last_pos() != (None, None))):
        abs_offset = distance(origin, PolylineObjectHandler._cache.get_last_pos())
    else:
        abs_offset = float('inf')
    is_old_cache = (lambda : (abs_offset > 8))
    new_dest_set = (lambda : (tuple(destination) != PolylineObjectHandler._cache.destination))
    if (PolylineObjectHandler._run and (not is_old_cache())):
        PolylineObjectHandler._instability -= 1
        if (PolylineObjectHandler._instability <= 0):
            PolylineObjectHandler._instability = 0
            PolylineObjectHandler._run = False
        pass
    elif ((None == PolylineObjectHandler._cache) or is_old_cache() or new_dest_set()):
        PolylineObjectHandler._instability += 2
        if (10 <= PolylineObjectHandler._instability):
            PolylineObjectHandler._run = True
            PolylineObjectHandler._instability = 20
        PolylineObjectHandler._cache = Polyline(origin, destination, google_map_api_key)
    else:
        PolylineObjectHandler._instability -= 1
        PolylineObjectHandler._instability = max(PolylineObjectHandler._instability, 0)
        pass
    return PolylineObjectHandler._cache
