Fix type relation caching

Fixes #1002.