Is is possible to cache the _deps folder?

Hi there,

I’m setting up CI for a project. It takes a couple of minutes to generate the project and a lot of that time is spent downloading content using FetchContent. Since this content is unlikely to change regularly, it seems like it’s a good candidate to be cached.

CircleCI makes caching easy with its save_cache and restore_cache commands. These commands take a key to identify the cache, which would typically be some kind of hash of some kind of lock file (e.g. key: npm-dependencies-{{ checksum "package-lock.json" }}).

My questions are as follows:

  • Is it reasonable to cache the _deps folder at all? Will that cause build artefacts to be maintained between runs? Will CMake recognise that it doesn’t need to download the dependencies again?
  • Is there some kind of file that I can use as a key that can be used to ‘break the cache’ when a dependency changes?

Thanks!

Yes, it’s absolutely reasonable to cache any fetched dependencies. I usually set FETCHCONTENT_BASE_DIR to projectRoot/Cache, so that while developing locally I can remove the build tree and dependencies will still be cached for the next CMake run.

Then, with GitHub actions, you can do this:

- name: Set up cache
        uses: actions/cache@v3
        with:
          path: Cache
          key: ${{ runner.os }}.tests.${{ hashFiles('**/') }}
          restore-keys: ${{ runner.os }}.tests.
1 Like