Refactor the state cache into the engine. This makes resource writing less error prone, and paves the way for better notifications.