Empty shopping cart when logged out and remember when logged in

hey, i just noticed when a user logs out, the shopping cart is still full of their purchases. how can i clear the shopping cart when user is logged out?

also, i want the shopping cart to remember their purchases when user logs back in. how do i do that too?