# Cache plugin for buildkite?

**URL:** <https://forum.buildkite.community/t/cache-plugin-for-buildkite/1324>\
**Category:** General\
**Created:** [November 5, 2020, 2:06pm UTC](https://forum.buildkite.community/t/cache-plugin-for-buildkite/1324 "2020-11-05T14:06:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leopradel](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/leopradel/32/885_2.png) [@leopradel](https://forum.buildkite.community/u/leopradel)\
**Post date:** [November 5, 2020, 2:06pm UTC](https://forum.buildkite.community/t/cache-plugin-for-buildkite/1324/1 "2020-11-05T14:06:50Z")

</div>

Hi all, I am currently trying to set up a caching mechanism to improve the pipelines of my NodeJs application.  
For example, this is how I am currently using it in Github actions for my open source repositories.

```
   - name: Get yarn cache directory path
    id: yarn-cache-dir-path
    run: echo "::set-output name=dir::$(yarn cache dir)"

  - uses: actions/cache@v2
    id: yarn-cache
    with:
      path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
      key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
      restore-keys: |
        ${{ runner.os }}-yarn-

```

What is the recommended way to do this using buildkite? I could not find any information in the documentation. Thanks!

---

<div class="post-metadata">

**Author:** ![vitalii](https://avatars.discourse-cdn.com/v4/letter/v/d6d6ee/32.png) [@vitalii](https://forum.buildkite.community/u/vitalii)\
**Post date:** [November 5, 2020, 2:55pm UTC](https://forum.buildkite.community/t/cache-plugin-for-buildkite/1324/2 "2020-11-05T14:55:50Z")

</div>

We’ve built a plugin internally just for this purpose (save/restore yarn & npm cache between builds): [https://github.com/peakon/s3-cache-buildkite-plugin](https://github.com/peakon/s3-cache-buildkite-plugin)

---

<div class="post-metadata">

**Author:** ![anon8263991](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@anon8263991](https://forum.buildkite.community/u/anon8263991)\
**Post date:** [November 6, 2020, 1:13am UTC](https://forum.buildkite.community/t/cache-plugin-for-buildkite/1324/3 "2020-11-06T01:13:26Z")

</div>

We don’t have an official caching method that’s equivalent to GitHub Actions approach, but there’s a number of plugins that work in a similar way.

@vitalii’s plugin is a good option. Another I’ve seen folks get positive results with [https://github.com/gencer/cache-buildkite-plugin](https://github.com/gencer/cache-buildkite-plugin)

Searching for “cache” on [https://buildkite.com/plugins](https://buildkite.com/plugins) might turn up some other options.

Sidenote: @vitalii - it’d be great to have peakon’s plugin listed in the plugin directory! If you’re up for it, there’s some instructions here: [https://buildkite.com/docs/plugins/directory](https://buildkite.com/docs/plugins/directory)

---

<div class="post-metadata">

**Author:** ![olegshilov](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/olegshilov/32/886_2.png) [@olegshilov](https://forum.buildkite.community/u/olegshilov)\
**Post date:** [November 6, 2020, 1:26am UTC](https://forum.buildkite.community/t/cache-plugin-for-buildkite/1324/4 "2020-11-06T01:26:51Z")

</div>

I’m using the `gencer/cache` plugin.  
My config looks like this.

```auto
cache_plugin_config: &cache_plugin_config
  backend: tarball
  key: "deps-{{ checksum 'yarn.lock' }}"
  tarball:
    path: '/tmp/buildkite-cache'
    max: 7 # Optional. Removes tarballs older than 7 days.
  paths:
    - ./node_modules/
    - ./packages/*/node_modules

steps:
  - label: ':eslint:'
    commands:
      - './ci yarn install --frozen-lockfile'
      - './ci yarn lint:web'
    plugins:
      - gencer/cache#v2.3.3: *cache_plugin_config

  - label: ':jest:'
    commands:
      - './ci yarn install --frozen-lockfile'
      - './ci yarn test:web --ci'
    plugins:
      - gencer/cache#v2.3.3: *cache_plugin_config

```

You can find more plugins here: [https://buildkite.com/plugins](https://buildkite.com/plugins)
