CacheTest big fixes

Travis is slow sometimes and the data in the cache could expire sooner than we want them to.
This also fixes the tests when php is run under valgrind.