Use a temporary cache for instances in :meth:`~.Expression.create`

    The instance cache used by :meth:`~.Expression.create` for any of the given
    `classes` will be cleared upon entering the managed context, and restored
    on leaving it.  That is, no cached instances from outside of the managed
    context will be used within the managed context, and vice versa

def temporary_instance_cache(*classes):
    """Use a temporary cache for instances in :meth:`~.Expression.create`

    The instance cache used by :meth:`~.Expression.create` for any of the given
    `classes` will be cleared upon entering the managed context, and restored
    on leaving it.  That is, no cached instances from outside of the managed
    context will be used within the managed context, and vice versa
    """
    orig_instances = []
    for cls in classes:
        orig_instances.append(cls._instances)
        cls._instances = {}
    try:
        yield
    finally:
        for i, cls in enumerate(classes):
            cls._instances = orig_instances[i]