factor cache out of cli.py