Cache to config

Complicated and lots of corners. Putting this here for reference. Not going to merge it.