# How to use python version or image name in cache key

**URL:** <https://discuss.circleci.com/t/how-to-use-python-version-or-image-name-in-cache-key/41108>\
**Category:** Caching Dependencies\
**Created:** [September 1, 2021, 9:32pm UTC](https://discuss.circleci.com/t/how-to-use-python-version-or-image-name-in-cache-key/41108 "2021-09-01T21:32:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [August 5, 2022, 4:47am UTC](https://discuss.circleci.com/t/how-to-use-python-version-or-image-name-in-cache-key/41108/3 "2022-08-05T04:47:58Z")

</div>

Seeing the same issue (and the discussion board help actually found this topic to offer me!)

I can’t use a composite key that includes, say, `{{ checksum ".venv/bin/python" }}`, because the restore job doesn’t yet have that file to compute the checksum on.

This basic idea works for me:

```yaml
commands:
  checkout-and-restore-deps:
    steps:
      - checkout
      - run: python --version > python_version
      - restore_cache:
          keys:
            - pipenv-v3-{{ .Branch }}-{{ checksum "Pipfile.lock" }}-{{ checksum "python_version" }}
            - pipenv-v3-{{ .Branch }}
            - pipenv-v3
jobs:
  restore-deps:
    executor: python
    environment: &common-env
      - PIPENV_VENV_IN_PROJECT: 1
      - PIPENV_NOSPIN: "TRUE"
    steps:
      - checkout-and-restore-deps
      - run:
          name: Wipe venv in case of stale symlink to old pyenv version
          command: |
            if [[-d .venv/bin]] && [[! -e .venv/bin/python]]
              then pipenv --rm
            fi
      - run: pipenv sync --dev
      - save_cache:
          key: pipenv-v3-{{ .Branch }}-{{ checksum "Pipfile.lock" }}-{{ checksum "python_version" }}
          paths:
            - ".venv"

```

---

_[View the full topic](https://discuss.circleci.com/t/how-to-use-python-version-or-image-name-in-cache-key/41108)._
