Backport cache invalidation fix (#487) to 0.9.x
Possible fix for #929 ?
Bah, forgot to move if
Merge pull request #945 from deniszh/0.9.x_cache_invalidation_fix

0.9.x cache invalidation fix