Make sure the test won't fail under Valgrind
Merge pull request #990 from sjinks/cache-test

CacheTest bug fixes