Re-using cache key

I have a workflow on a monorepo that has multiple package.json files. the cache key looks something like this:

    - restore_cache:
          keys:
            - some-prefix-{{ checksum "package-lock.json" }}-{{
              checksum "apps/app1/package-lock.json" }}-{{
              checksum "apps/app2/functions/package-lock.json" }}

this cache key appears many times in my config.yml file.

I’m wondering if it’s possible to declare the cache key in one location and save it as a variable, and then referencing it in multiple locations. Something like this:

    - restore_cache:
          keys:
            - << my-saved-cache-key >>

Is this possible, and what what would be the syntax? Any references do documentation for declaring a local variable like this would be helpful. Thanks!

There was an answer to using environment variables in config.yml that linked to the following example file.

 https://github.com/drevops/drevops/blob/8.x/.circleci/config.yml

This is an example of the use of aliases that may allow you to do what you want, more info is exchanged in this old thread

https://discuss.circleci.com/t/how-can-steps-in-yaml-config-be-reused/21876/4

and this blog post

YAML - config.yml | CircleCI

It can’t be done exactly how you want, but there are many alternative ways.

  1. via YAML, see @rit1010 post
  2. via CircleCI reusable config: Reusable Config Reference Guide - CircleCI
  3. Via orbs, which is really #2 but in an orb