# How to have a separate cache per workflow?

**URL:** <https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517>\
**Category:** Question & Answer\
**Tags:** build-cache\
**Created:** [December 13, 2017, 10:09pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517 "2017-12-13T22:09:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rraallvv](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/rraallvv/32/1022_2.png) [@rraallvv](https://discuss.bitrise.io/u/rraallvv)\
**Post date:** [December 13, 2017, 10:09pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/1 "2017-12-13T22:09:29Z")

</div>

What I want is to have two workflows each with a different cache.

Using `printenv` on a macOS box I found `$BITRISE_CACHE_DIR` and `$BITRISE_CACHE_API_URL`, also some scripts use `$BITRISE_CACHE_INFO_PATH` but it’s not clear whether those variables can be changed to point to separate caches.

This is how I’ve setup bitrise.yml in my repository:

```auto
format_version: "4"

default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

project_type: other

#trigger_map:
# - push_branch: '*'
# workflow: primary
# - pull_request_source_branch: '*'
# workflow: primary

app:
  envs:
    - SCONS_CACHE: $HOME/.scons_cache
    - SCONS_CACHE_LIMIT: 1024
    - CC: clang
    - CXX: clang++
    - GODOT_TARGET: osx
    - TOOLS: yes

workflows:
# primary:
# steps:
# - activate-ssh-key@3.1.1:
# run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
# - git-clone@3.6.2: {}
# - script@1.1.5:
# title: Do anything with Script step
# - deploy-to-bitrise-io@1.3.9: {}

  build:
    steps:
      - cache-pull:
          inputs:
            - cache_paths: |-
                $SCONS_CACHE
      - script@1.1.5:
          title: Build script
          inputs:
            - content: |-
                echo $BITRISE_CACHE_DIR
                echo $BITRISE_CACHE_API_URL
                echo $BITRISE_CACHE_INFO_PATH
                mkdir -p $SCONS_CACHE
                misc/bitrise/scons-local-osx.sh
                scons -j 2 CC=$CC CXX=$CXX platform=$GODOT_TARGET TOOLS=$TOOLS verbose=yes progress=no;
      - cache-push:
          inputs:
            - cache_paths: |-
                $SCONS_CACHE

```

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [December 15, 2017, 12:06pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/2 "2017-12-15T12:06:24Z")

</div>

Hi @rraallvv,

Thanks for the question! 🙂

> What I want is to have two workflows each with a different cache.

Unfortunately that’s not possible. Cache storage is allocated for **branches** , not workflows. It’s automatic, every branch when pushes a cache to the API will create its own cache (will not overwrite another branch’s cache), but it’s always allocated by `branch`.

Related docs: [Redirecting… - Bitrise Docs](http://devcenter.bitrise.io/caching/about-caching/)

If you’d have any questions just let us know! 🙂

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [December 15, 2017, 12:10pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/3 "2017-12-15T12:10:29Z")

</div>

That said, checking your example `bitrise.yml` in your question, are you sure you need/want per workflow cache? It should definitely work with just per-branch cache, at least in the example I don’t see any reason why it might not.

If you have a specific error please copy paste the related build’s [bitrise.io](http://bitrise.io) URL and we’ll check it ASAP! 🙂

P.S.: in the example you have `cache_paths` in the “Cache:Pull” step too; that step does not have that input, the cache:pull step simply moves the caches to the original location, the one which was defined in the **Cache:Push** step.

In short you control the cache config (what to cache) in the **Cache:Push** step, which stores these infos in the cache archive; the **Cache:Pull** step simply reads that meta-info and uncompresses the cache archive to the original locations/paths.

---

<div class="post-metadata">

**Author:** ![rraallvv](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/rraallvv/32/1022_2.png) [@rraallvv](https://discuss.bitrise.io/u/rraallvv)\
**Post date:** [December 15, 2017, 1:10pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/4 "2017-12-15T13:10:53Z")

</div>

I was hoping maybe I could have separate caches for macOS and iOS for the same branch. I’ve seen parallel builds [are not possible](http://discuss.bitrise.io/t/how-to-trigger-multiple-workflows-at-the-same-time/3401?u=rraallvv) out of the box but I’ll try the workaround described by @koral. Regarding the separate caches issue, I’ll have to use separate folders for each build then. I’m going to remove the input in cache-pull. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [December 19, 2017, 8:37am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/5 "2017-12-19T08:37:34Z")

</div>

> [@rraallvv](#):
>
> I’ve seen parallel builds are not possible out of the box

Indeed, not yet available as a built in feature, but definitely planned for the near future. Please vote & comment at [Parallel Builds: trigger multiple workflows (builds) at the same time - build stages - fan-out fan-in support - #20 by viktorbenei](http://discuss.bitrise.io/t/parallel-builds-seperate-stacks-for-seperate-workflows-trigger-multiple-workflows-builds-at-the-same-time/410/20) to bump its priority (although at this point it definitely is planned for early next year).

If you have any questions just let us know! 🙂

---

<div class="post-metadata">

**Author:** ![rraallvv](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/rraallvv/32/1022_2.png) [@rraallvv](https://discuss.bitrise.io/u/rraallvv)\
**Post date:** [December 19, 2017, 2:02pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/6 "2017-12-19T14:02:42Z")

</div>

@viktorbenei thanks for the info.

---

<div class="post-metadata">

**Author:** ![max](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@max](https://discuss.bitrise.io/u/max)\
**Post date:** [April 30, 2019, 11:45am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/7 "2019-04-30T11:45:39Z")

</div>

Hey,

I would like to bump this thread with more sophisticated usage pattern:

I am using job with multiple workflows. The entry workflow is triggering few others via `build-router-start`. That is one per `ios` and one per `android`. I would love to be able to have separate caches per workflow. For instance: I want to cache `Pods` for `ios` workflow but I don’t care about pods in `android` flow.

Any way to achieve this today? Perhaps something changed since previous answer?

---

<div class="post-metadata">

**Author:** ![bitce](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bitce/32/1639_2.png) [@bitce](https://discuss.bitrise.io/u/bitce)\
**Post date:** [May 3, 2019, 8:06am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/8 "2019-05-03T08:06:30Z")

</div>

Hi @max!

There weren’t any changes to the main feature, the link posted above by @viktorbenei is up to date, so you can check out the current detailed behaviour here: [https://devcenter.bitrise.io/caching/about-caching/](https://devcenter.bitrise.io/caching/about-caching/)

But in short cache does not work per workflow, it does per branch, so you could only achieve this if you were to separate your ios and android code you build per branch too.

---

<div class="post-metadata">

**Author:** ![AlaaEddineCharbib](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/alaaeddinecharbib/32/3021_2.png) [@AlaaEddineCharbib](https://discuss.bitrise.io/u/AlaaEddineCharbib)\
**Post date:** [June 17, 2020, 4:45pm UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/9 "2020-06-17T16:45:46Z")

</div>

I believe caching per Branch will not be super useful, in our case we create branches for each feature and and we make builds from those branches (without pull request)  
if we have to download again from scratch for every new branch we create before having cache available, then it will not really save us much time.  
having cache per workflow or by App would save lot of time and build resources  
Is there at least a possibility to define in cache pull step where the cache should be pulled from (ex pulling from develop’s cache while building another branch)?

---

<div class="post-metadata">

**Author:** ![bitce](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bitce/32/1639_2.png) [@bitce](https://discuss.bitrise.io/u/bitce)\
**Post date:** [June 25, 2020, 10:29am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/10 "2020-06-25T10:29:03Z")

</div>

Hi @AlaaEddineCharbib! This is not possible at the moment, but thanks for your feedback! I’ve made sure we take a note of it.

---

<div class="post-metadata">

**Author:** ![DaBs](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/dabs/32/3118_2.png) [@DaBs](https://discuss.bitrise.io/u/DaBs)\
**Post date:** [August 20, 2020, 8:25am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/11 "2020-08-20T08:25:52Z")

</div>

This feature is highly requested for us, but we’re actually imagining it slightly more granular. If you could simply name a cache, and thus push and pull named caches, you’d solve the issue, at least according to our needs. We currently want to have a cache for our base workflow with npm packages, a cache for our iOS workflow and a cache for our Android workflow. I realized that scoping it per workflow would work perfectly fine here as well, but I think the naming would provide a large amount of flexibility to the caching solution.

Thanks for listening to the feedback though!

---

<div class="post-metadata">

**Author:** ![ibrahim.chraibi](https://avatars.discourse-cdn.com/v4/letter/i/9fc29f/32.png) [@ibrahim.chraibi](https://discuss.bitrise.io/u/ibrahim.chraibi)\
**Post date:** [December 28, 2020, 10:33am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/12 "2020-12-28T10:33:52Z")

</div>

+1 I think having the ability to push/pull cache by a specific key and be able to use it through different branches would make caching way more flexible 🙂 (this also how it’s normally handled by some other other CI/CD platforms that offers cashing solutions)

---

<div class="post-metadata">

**Author:** ![denizbilgin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@denizbilgin](https://discuss.bitrise.io/u/denizbilgin)\
**Post date:** [December 14, 2021, 9:54am UTC](https://discuss.bitrise.io/t/how-to-have-a-separate-cache-per-workflow/3517/13 "2021-12-14T09:54:31Z")

</div>

Isn’t it extremely common to have branches for every feature separately? What use case would this caching system be helpful for? First merging and then testing?
