Help to create a job to install yarn dependencies

Hello,

I have a small question, I wanted to create a job to install the yarn dependencies. So that then the other jobs just have to execute the commands.

config.yml

version: 2.1

executors:
  machine:
    docker:
      - image: cimg/node:lts

jobs:
  prepare-dependencies:
    executor: machine
    steps:
      - checkout

      - restore_cache:
          keys:
            - yarn-v1-{{ checksum "yarn.lock" }}

      - run:
          name: Install dependencies
          command: yarn --frozen-lockfile --cache-folder ~/.cache/yarn

      - save_cache:
          key: yarn-v1-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn

      - persist_to_workspace:
          root: .
          paths: .

  test:
    executor: machine
    steps:
      - attach_workspace:
          at: .

      - run:
          name: Run tests
          command: yarn test

workflows:
  version: 2
  development:
    jobs:
      - prepare-dependencies
      - test:
          requires:
            - prepare-dependencies

Is there a better, more optimal way?