# Precisions on how caching works

**URL:** <https://discuss.bitrise.io/t/precisions-on-how-caching-works/17058>\
**Category:** Question & Answer\
**Created:** [June 1, 2021, 8:50pm UTC](https://discuss.bitrise.io/t/precisions-on-how-caching-works/17058 "2021-06-01T20:50:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![frederic.camblor](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/frederic.camblor/32/3575_2.png) [@frederic.camblor](https://discuss.bitrise.io/u/frederic.camblor)\
**Post date:** [June 1, 2021, 8:50pm UTC](https://discuss.bitrise.io/t/precisions-on-how-caching-works/17058/1 "2021-06-01T20:50:50Z")

</div>

Hi there ✋

I’m playing with Cache Push / Pull steps and I must admit I’m not sure to understand how update indicators are working.

Typically, let’s say I have a `package.json` file used to fill a `node_modules` directory.  
For this, I defined following path configuration :

```auto
./node_modules/ -> ./package.json

```

I would like to :

- Cache `node_modules` directory content
- Update its content (with PUSH step) in the cache everytime `package.json` is altered
- Load its content (with PULL step) from the cache only if my local `package.json` checksum differs from the one I used to PUSH `node_module` content.

During my tests, it appeared that the PULL step is systematically retrieving the cache content, regardless of if `package.json` has changed or not since my latest PUSH to the cache.  
(it’s as if update indicators were used for PUSHes only, and never for PULLs)

Am I wrong in my assumptions ?

---

<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:** [June 11, 2021, 12:37pm UTC](https://discuss.bitrise.io/t/precisions-on-how-caching-works/17058/2 "2021-06-11T12:37:14Z")

</div>

Hello @frederic.camblor 👋

You are correct, the Cache:Pull step loads whatever in the cache every time it runs, regardless of any updates. If it did not the virtual machine would have no cache to utilize at all, since every build starts with a clean environment and is destroyed after the end of every build.

You CAN, however, make the Cache:Pull step run conditionally, if you prefer: [Enabling or disabling a Step conditionally | Bitrise DevCenter](https://devcenter.bitrise.io/steps-and-workflows/disable-a-step-by-condition/)

This way you could perhaps create an env var in a script step which checks if there are any differences in the package.json since the last build (which you can reach via an API call: [https://api-docs.bitrise.io/](https://api-docs.bitrise.io/)), and set up a condition to only run the Cache:Pull step when there is one.

Hope this helps! 🙂

---

<div class="post-metadata">

**Author:** ![frederic.camblor](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/frederic.camblor/32/3575_2.png) [@frederic.camblor](https://discuss.bitrise.io/u/frederic.camblor)\
**Post date:** [June 11, 2021, 1:08pm UTC](https://discuss.bitrise.io/t/precisions-on-how-caching-works/17058/3 "2021-06-11T13:08:58Z")

</div>

Thanks 🙂

The idea would be to store package.json “state” (its checksum for example) into a build “resulting” variable, which may be accessible through the API ?

I’m not sure if build “resulting” variable are available through **/apps/{app-slug}/builds/{build-slug}** API  
Maybe consider package.json as a generated artefact and retrieve it through **/apps/{app-slug}/builds/{build-slug}/artifacts + /apps/{app-slug}/builds/{build-slug}/artifacts/{artifact-slug}**?

---

<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:** [July 11, 2021, 1:08pm UTC](https://discuss.bitrise.io/t/precisions-on-how-caching-works/17058/4 "2021-07-11T13:08:59Z")

</div>

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