Using cache for saving edges