<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def pop_stream(cache, user_id):
 """ Pop an item off the stack in the cache. If stack is empty after pop, it deletes the stack. :param cache: werkzeug BasicCache-like object :param user_id: id of user, used as key in cache :return: top item from stack, otherwise None """

    stack = cache.get(user_id)
    if stack is None:
        return None

    result = stack.pop()

    if len(stack) == 0:
        cache.delete(user_id)
    else:
        cache.set(user_id, stack)

    return result