backport of cache changes from 0.6