Refactor cache and relays