# Disable fallback to default branch when restoring the cache

**URL:** <https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** caching\
**Created:** [September 21, 2019, 8:21pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093 "2019-09-21T20:21:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lys](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lys/32/1188_2.png) [@lys](https://travis-ci.community/u/lys)\
**Post date:** [September 21, 2019, 8:21pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/1 "2019-09-21T20:21:53Z")

</div>

> [@Cache is unexpectedly fetched from another branch](https://travis-ci.community/t/cache-is-unexpectedly-fetched-from-another-branch/3859/2):
>
> As per [https://docs.travis-ci.com/user/caching/#fetching-and-storing-caches](https://docs.travis-ci.com/user/caching/#fetching-and-storing-caches), 8.9 is used as a fallback because it’s set as the default branch for your Github repo.

Is there a way to disable this fallback? I really don’t want to fetch from any other branches.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [September 23, 2019, 2:44am UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/2 "2019-09-23T02:44:08Z")

</div>

Why? If the cache is not found in the fallback (the default branch), nothing will be downloaded, and your job should proceed. The overhead for this check should be a couple of seconds, tops.

And if your non-default-Branch proceeds to create a cache, it will be uploaded as one that is used by that branch and nothing else.

---

<div class="post-metadata">

**Author:** ![lys](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lys/32/1188_2.png) [@lys](https://travis-ci.community/u/lys)\
**Post date:** [September 23, 2019, 2:58am UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/3 "2019-09-23T02:58:51Z")

</div>

Unwanted cache might be incompatible packages that I have to uninstall before installing the right version, which leads to even larger overhead.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [September 23, 2019, 12:45pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/4 "2019-09-23T12:45:39Z")

</div>

Then you can put a different `.travis.yml` in the non-default branch that disables (or defines a different) cache.

---

<div class="post-metadata">

**Author:** ![lys](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lys/32/1188_2.png) [@lys](https://travis-ci.community/u/lys)\
**Post date:** [September 23, 2019, 2:19pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/5 "2019-09-23T14:19:22Z")

</div>

The `.travis.yml` configurations are already different:

> <https://github.com/QuickChick/QuickChick/blob/af2aec45b342cd31d6f50363a53f20e42382e7e7/.travis.yml#L13>

  

> <https://github.com/QuickChick/QuickChick/blob/44f483f644f462379653bee6153b2339f94ba3c5/.travis.yml#L15>

  
but `8.10` build still [fetched cache from `8.9`](https://travis-ci.org/QuickChick/QuickChick/jobs/587972574#L189) (default branch).

How should I define a different cache?

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [September 23, 2019, 2:51pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/6 "2019-09-23T14:51:03Z")

</div>

I understand the general concern, but this is a problem only if you have a default-cache that **actively** prevents a non-default branch from building. Then I’d imagine that deleting the cache should resolve the issue.

As for your present problem with the 8.10 branch, I note that no cache is actually being used [https://travis-ci.org/QuickChick/QuickChick/jobs/587972574#L191](https://travis-ci.org/QuickChick/QuickChick/jobs/587972574#L191) Once you have a job complete, it should upload its own cache, which will be used in subsequent jobs.

---

<div class="post-metadata">

**Author:** ![lys](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lys/32/1188_2.png) [@lys](https://travis-ci.community/u/lys)\
**Post date:** [September 23, 2019, 6:39pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/7 "2019-09-23T18:39:38Z")

</div>

Maybe my solution should be:

1. Delete cache on default branch;
2. Have successful build on non-default branches, to warm their caches up; and
3. Expect non-default branches not to fetch cache from default branch any more.

Will take a try on that.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [September 23, 2019, 7:36pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/8 "2019-09-23T19:36:23Z")

</div>

> [@Cache is unexpectedly fetched from another branch](https://travis-ci.community/t/cache-is-unexpectedly-fetched-from-another-branch/3859/9):
>
> Maybe my solution should be:

> [@BanzaiMan](#):
>
> this is a problem only if you have a default-cache that **actively** prevents a non-default branch from building

@lys, what @BanzaiMan means is normally, the build logic is designed in such a way that it automatically creates a correct environment and validates any existing stuff before reusing it (installs the right module versions, creates versioned build artifacts etc). So if correct stuff is already present, those operations become no-ops and if incorrect stuff is present, it will be ignored or automatically overwritten.

---

<div class="post-metadata">

**Author:** ![lys](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lys/32/1188_2.png) [@lys](https://travis-ci.community/u/lys)\
**Post date:** [September 23, 2019, 8:42pm UTC](https://travis-ci.community/t/disable-fallback-to-default-branch-when-restoring-the-cache/6093/9 "2019-09-23T20:42:51Z")

</div>

You’re right. I’ve used the wrong example. Will follow up after my problem pins down.
