Skip to content

Latest commit

 

History

History
100 lines (67 loc) · 2.66 KB

LAB.md

File metadata and controls

100 lines (67 loc) · 2.66 KB

🔌 Lab 16 - Distributed caching

⏰  Estimated time: 10 minutes

📚 Learning outcomes:

  • Understand the difference between local and distributed caching
  • Learn how to add NxCloud and enable distributed on an existing Nx workspace

🏋️‍♀️ Steps :

  1. Earlier in the workshop, we discussed about Nx's local caching capabilities. Let's enable distributed caching.

    nx connect-to-nx-cloud
    

    Nx Cloud Confirmation


  1. Inspect the changes added in nx.json - especially the access token. We'll explain that more in a bit!

  1. Very important: Make sure, at this stage, you commit and push your changes:

    # make sure you're on master
    git checkout master
    git add . && git commit -m "add nx cloud"
    git push origin master
    

  1. Run a build: nx run-many --target=build --all

    🕑 Watch the process in the terminal - it might take a few seconds...


  1. You'll see a link at the end, let's see what's there:

    Run Details Link

    We'll talk more about these links later!


  1. Try to build all projects again: nx run-many --target=build --all

    ⚡ It should finish much quicker this time - because it just pulled from the local cache!


  1. Let's try something different now - in a different folder on your machine, let's try and do a fresh of your repository:

    # go into a new folder
    cd ..
    # clone your repo again
    git clone [email protected]:<your-username>/<your-repo>.git test-distributed-caching
    cd test-distributed-caching
    # install dependencies
    yarn
    

  1. In your new instance, let's try and build again: nx run-many --target=build --all

    ⚡ It should be almost instant...


  1. But how? You have no local cache: we just did a fresh pull of the repository.

    Check your terminal output - you should see this message:

    NxCloud cache pull

    That means that instead of rebuilding locally again, we just pulled from the distributed cache.


  1. Let's try a different command - in the same folder you are in, try to run:

    nx run-many --target=lint --all
    

    🕑 It should start the linting work, and take a few seconds...


  1. Now let's go back to our main workshop repository and run:

    nx run-many --target=lint --all
    

    ⚡ It should pull again from the NxCloud cache...This is even works across laptops! CI will use it as well!



➡️  Next lab ➡️