Refactor CacheBuilder

Use extract method to make the cache building process more clear