Cache managed entities

Fixes #1 and a bit of #3.