Docker cache not working for more than a single docker build command in a build

Hi,
My build is building two different docker images.
The repo structure is:

Root

  • A
    dockerfile
  • B
    dockerfile

The config.yml starts with the cache command:

- setup_remote_docker:
       docker_layer_caching: true

Then I have two steps like:

- run:
          name: Build A
          command: docker build -t brand/A:$CIRCLE_BUILD_NUM .
          working_directory: A
- run:
          name: Build B
          command: docker build -t brand/B:$CIRCLE_BUILD_NUM .
          working_directory: B

In each docker file I have these steps:

COPY package.json .
COPY yarn.lock .

RUN yarn

COPY . .

RUN yarn run build-ci

Now if I run the build without any change in code, all docker command use the cache. If I run the build only with changes in directory B, A commands are using the cache but B commands are not (after the change was copied) which is expected.
The problem is that if I run the build after a change only in directory A, and A commands don’t use the cache, B commands also don’t use the cache although there was no change inside B folder.

Any idea why?
Thanks