How mount cache Buildkit actually works

The document mentions that mount cache solves the problem likes

when installing packages, you don’t always need to fetch all of your packages from the internet each time. You only need the ones that have changed

Can someone explain to me what “installing packages” exactly means. Take yarn for example, I’ve tried

RUN --mount=type=cache,target=/root/.yarn yarn install --production && yarn add lodash

the lodash installation is a test to see whether buildkit just add lodash when rebuild but it just use the cache.