Search code examples
azurecachingazure-devopsazure-pipelinesazure-caching

Can I configure 'Cache' task in Azure Pipelines to only restore the cache and not the save the cache?


I want to configure the 'Cache' task in Azure Pipelines to only restore the cache and not the save the cache and vice versa? Is there any workaround for this scenario?

I read the documentation regarding caching but didn't find any solution


Solution

  • I want to configure the 'Cache' task in Azure Pipelines to only restore the cache and not the save the cache.

    The cache task is already doing this way.

    It evaluates the key to identifier for the cache you want to restore or save, when the key is same, there's a cachehit, it will restore the cache, and at the end Post-job: Cache" step, it reports: Cache with fingerprint xxxx already exists, and will skip saving.

    enter image description here

    When key is changed, it will evaluate restoreKeys in cache task, when it's met, it's a partial cache hit, it will also restore the cache content, but at end Post-job: Cache" step, the Cache with fingerprint value is differnet, it will still save the content. enter image description here

    enter image description here

    You can remove restorekeys in cache task, so that it will only evaluate for key value to determine restore or not.

    If both key and restorekeys value is NOT met, it's cache miss, it will NOT restore the cache content, and save content at last Post-job: Cache" step.

    More details please check doc Pipeline caching.