More robust caching

See #191