rebase to Mandy's code, remove FlattenedWeakCache and interface