Refactor cacheImpl and Vertex, improve rebuild