Implement shape_plan caching

Should give us some performance boost.
7 files changed