How to use actions/cache@v2 in a matrix job

I have a build matrix job which runs the npm install basically its a monorepo I would like to cache the node_modules across the matrix jobs, should I have a separate job before the matrix job to just cache and then run my matrix or is there any better way to cache between the matrix job runs to achieve maximum parallelism.