# Clearing build cache

**URL:** <https://discuss.bitrise.io/t/clearing-build-cache/18149>\
**Category:** Question & Answer\
**Created:** [September 30, 2021, 3:30pm UTC](https://discuss.bitrise.io/t/clearing-build-cache/18149 "2021-09-30T15:30:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcGrenierIntact](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@MarcGrenierIntact](https://discuss.bitrise.io/u/MarcGrenierIntact)\
**Post date:** [September 30, 2021, 3:30pm UTC](https://discuss.bitrise.io/t/clearing-build-cache/18149/1 "2021-09-30T15:30:26Z")

</div>

Hello, I’m looking into automating clearing the build cache from a workflow instead of going in the settings and manually deleting the cache.

I tried creating a workflow that would only do a “cache-push” step and nothing else. But that didn’t seem to clear it.

Anyone know of another way?

---

<div class="post-metadata">

**Author:** ![Roland-Bak](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/roland-bak/32/3480_2.png) [@Roland-Bak](https://discuss.bitrise.io/u/Roland-Bak)\
**Post date:** [October 21, 2021, 11:28am UTC](https://discuss.bitrise.io/t/clearing-build-cache/18149/2 "2021-10-21T11:28:34Z")

</div>

Hello @MarcGrenierIntact 👋

Currently there is no step or any other automatized option to delete your cache, though they do get automatically deleted after 7 days if unused.  
Could you give a bit more detail as to why you would need this feature? You can also have workflows that simply don’t include the Cache:Pull step (and this not use cache), or you can give a condition to the step to only run in certain conditions: [Enabling or disabling a Step conditionally | Bitrise DevCenter](https://devcenter.bitrise.io/steps-and-workflows/disable-a-step-by-condition/)

---

<div class="post-metadata">

**Author:** ![MarcGrenierIntact](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@MarcGrenierIntact](https://discuss.bitrise.io/u/MarcGrenierIntact)\
**Post date:** [October 21, 2021, 12:28pm UTC](https://discuss.bitrise.io/t/clearing-build-cache/18149/3 "2021-10-21T12:28:48Z")

</div>

Hi @Roland-Bak 👋

Thanks for the feedback! My team needs this feature because we support multiple internal libraries that in one of our project are updated pretty frequently (multiple times a day). This causes our cache to grow in size pretty rapidly. From less than 2 GB on the first cache push to more than 8GB in 2 weeks. So doing a clean up once every week or two would ensure us that our cache is clean and takes a reasonable time to pull and push.

The good news is that I found an easy way to do this. Here are the steps in case anyone sees this post in the futur :

1. Download your cache in “Settings \> Manage Build caches” and check which paths are being cached.
2. Create a new empty workflow
3. Add a script step and a cache push step
4. In the script step create the directories you would want to be cleaned from the cache. For me, it was the ~/.gradle directory. I also added a bit of logic to only run the script every 2 weeks.
5. Add this path to the “Cache paths” of the cache push step.
6. Schedule a build every week on the branch that has the cache.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/d901cf2aad020f2dd11918afc89ec2089bb87b35.png) [@system](https://discuss.bitrise.io/u/system)\
**Post date:** [November 20, 2021, 12:29pm UTC](https://discuss.bitrise.io/t/clearing-build-cache/18149/4 "2021-11-20T12:29:06Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
