I'm pretty sure that the mind has short-term and long-term storage.
A place for the inputs of the day to be quickly shoved into without too much sorting and categorising. And then when you sleep your brain has time to sift through it all and make links to other events stored away.
And so you get that weird effect of having an unsolvable problem at work, and then when you wake up the next morning you magically have a solution.
I think there are several layers of "cache", to use a computing term.
I have had times when I've woken up at night. Perhaps due to a noise outside. Peeked out the window and talked to my wife for a bit, then gone back to sleep, and completely forgotten about it in the morning, with my wife trying to talk to me about it. With going to sleep, that short term cache of events was just wiped. I have talked to people who had serious surgery and were going in an out of conciousness with drugs, and they don't remember the concious bits at all.
The brain using complicated tricks to absorb vast amounts of data, and then store, sort, categorise it all.