Replace InMemoryCache with new impl that avoids read under write races

Addresses some points in #1260.

This was PR #1302.
3 files changed