# Caching among steps

**URL:** <https://forum.buildkite.community/t/caching-among-steps/3723>\
**Category:** Pipelines\
**Created:** [June 3, 2024, 4:36am UTC](https://forum.buildkite.community/t/caching-among-steps/3723 "2024-06-03T04:36:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![son.propte](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@son.propte](https://forum.buildkite.community/u/son.propte)\
**Post date:** [June 3, 2024, 4:36am UTC](https://forum.buildkite.community/t/caching-among-steps/3723/1 "2024-06-03T04:36:50Z")

</div>

Hi Buildkite team,

I have an issue when running a pipeline. The pipeline takes too long time to run, initialize steps. Every step need to be initialized with the same work such as cloned repository, install docker container, install node\_modules,… The next steps don’t inherit the state from the previous steps.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/4/4971f8b48bc84b8624a2829a40a290c72d4cd82f.png)

I would like to know if there is a way to cache its state among steps and don’t need to initialize before running a new step.

Thank you.

---

<div class="post-metadata">

**Author:** ![lizette](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/lizette/32/1161_2.png) [@lizette](https://forum.buildkite.community/u/lizette)\
**Post date:** [June 3, 2024, 5:31am UTC](https://forum.buildkite.community/t/caching-among-steps/3723/2 "2024-06-03T05:31:12Z")

</div>

Hi @son.propte,

There are many ways to address this. If the issue is just taking too long to clone a repo, you can use [git-mirrors](https://buildkite.com/docs/agent/v3#promoted-experiments-git-mirrors) feature , or if you want the jobs steps to run on the same agent that performed the `pipeline upload`, you can make use of the [node-affinity](https://buildkite.com/docs/agent/v3/cli-start#run-a-job-on-the-agent-that-uploaded-it-also-known-as-node-affinity) feature.

Cheers!

---

<div class="post-metadata">

**Author:** ![muratgozel](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@muratgozel](https://forum.buildkite.community/u/muratgozel)\
**Post date:** [June 4, 2024, 7:18am UTC](https://forum.buildkite.community/t/caching-among-steps/3723/3 "2024-06-04T07:18:07Z")

</div>

I was going to ask the same question and just tried the “node-affinity” feature to get the benefit of storing the npm dependencies in the same directory across buildkite steps.

I did as this doc says:

> **[buildkite-agent start v3](https://buildkite.com/docs/agent/v3/cli-start#run-a-job-on-the-agent-that-uploaded-it-also-known-as-node-affinity)**
>
> The Buildkite Agent's start command is used to manually start an agent and register it with Buildkite.

And the pipeline has 3 steps that contains dependency installation:

```yml
  ...
  command: .buildkite/unit_tests.sh # contains `pnpm install`
  agents:
      hostname: "$BUILDKITE_AGENT_META_DATA_HOSTNAME"
  ...

```

Also configured a root dir for pnpm in the `agent-startup` hook:

```sh
pnpm config set store-dir ~/.pnpm-store

```

however, the steps still taking 25 seconds and im able to see they are just installation of dependencies.

---

<div class="post-metadata">

**Author:** ![karen.sawrey](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/karen.sawrey/32/1188_2.png) [@karen.sawrey](https://forum.buildkite.community/u/karen.sawrey)\
**Post date:** [June 4, 2024, 9:25am UTC](https://forum.buildkite.community/t/caching-among-steps/3723/4 "2024-06-04T09:25:15Z")

</div>

Hello, @muratgozel! Could you please send a link to that pipeline to [support@buildkite.com](mailto:support@buildkite.com) for us to take a closer look?

Best!  
Karen
