nerdexam
Microsoft

AZ-400 · Question #590

Hotspot Question You have an Azure subscription that contains Azure DevOps build pipelines. You need to implement pipeline caching by using the cache task. How should you complete the YAML definition?

The correct answer is 'yarn' | "$(Agent.OS)" | yarn.lock': key:; $(YARN_CACHE_FOLDER): path:. This question tests knowledge of implementing pipeline caching in Azure DevOps using the Cache task in a YAML pipeline definition. The Cache task reduces build time by reusing files from previous runs when the cache key hasn't changed.

Submitted by klara.se· Mar 6, 2026Design and implement build and release pipelines

Question

Hotspot Question You have an Azure subscription that contains Azure DevOps build pipelines. You need to implement pipeline caching by using the cache task. How should you complete the YAML definition? To answer, select the appropriate options in the answer area. NOTE: Each correct selection is worth one point. Answer:

Exhibit

AZ-400 question #590 exhibit

Answer Area

  • 'yarn' | "$(Agent.OS)" | yarn.lock'key:
    element:item:key:restoreKeys:
  • $(YARN_CACHE_FOLDER)path:
    directory:folder:location:path:

Explanation

This question tests knowledge of implementing pipeline caching in Azure DevOps using the Cache task in a YAML pipeline definition. The Cache task reduces build time by reusing files from previous runs when the cache key hasn't changed.

Approach. The correct YAML structure for the Cache task requires 'task: Cache@2' as the task identifier with version 2, followed by 'inputs:' containing three key properties: 'key' (a unique identifier for the cache, typically using a hash of dependency files like package-lock.json), 'restoreKeys' (fallback keys if the exact key isn't found), and 'path' (the directory to cache, such as $(npm_config_cache) or node_modules). The key is usually defined using a pipe-delimited string combining the OS, a literal string, and a file hash like '"npm" | "$(Agent.OS)" | package-lock.json' to ensure cache validity across different environments and dependency changes.

Concept tested. Azure DevOps pipeline caching using the Cache@2 task in YAML pipelines, including proper syntax for cache key definition, restore keys, and cache path configuration to optimize build performance.

Reference. https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops

Topics

#pipeline caching#YAML pipeline#cache task#Azure Pipelines

Community Discussion

No community discussion yet for this question.

Full AZ-400 Practice