Fix invalidate cache function and fix tests.