# glov-build-cache

> Git-commit-able caching wrapper for slow build tasks

Latest version **1.2.0** (published 2026-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install glov-build-cache
pnpm add glov-build-cache
yarn add glov-build-cache
bun add glov-build-cache
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2026-09-02 |
| First published | 2023-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Jimb Esser |
| Maintainers | jimbly |
| Keywords | glov-build, glov, glovjs |

## Links

- npm: https://www.npmjs.com/package/glov-build-cache
- Repository: https://github.com/Jimbly/npm-publish
- Homepage: https://github.com/Jimbly/glov-build-cache#readme
- Issues: https://github.com/Jimbly/npm-publish/issues
- npm.io page: https://npm.io/package/glov-build-cache

## Dependencies (1)

- [glov-async](https://npm.io/package/glov-async.md) ^1.0.3

## Recent versions

- 1.2.0 (latest) — 2026-09-02
- 1.1.1 — 2026-08-31
- 1.1.0 — 2023-04-21
- 1.0.0 — 2023-01-25

## README

Git-commit-able caching wrapper for slow [glov-build](https://github.com/Jimbly/glov-build) tasks
=============================

Though [glov-build](https://github.com/Jimbly/glov-build) is already highly cached and only reprocesses exactly the files needed to be reprocessed on your machine, some tasks (such as `imagemin`) are so slow that you do not want to have to run them even once on a new developer's machine, or on a build system (which may be unable to take advantage of a local cache between runs).

This task wrapper is for caching single-input tasks such as image minification or other image postprocessing.  Tasks that output multiple outputs (such as a .wav -> .ogg + .mp3 conversion task) are also supported, as long as they are of type `gb.SINGLE`.

Any job will be re-run if the hash of the input file has changed, or any of the deps recorded in the previous run have changed, or the task version has changed (no hashing of the child task's func, or it's version number, etc, is done).

API usage:
```javascript
const gbcache = require('glov-build-cache');

gb.task({
  name: 'name',
  input: '*.png',
  ...gbcache({
    key: 'cache-key',
    version: 1,
    cache_root: './.gbcache',
    gzexts: ['.dds'],
    do_cache_write: false,
    do_cache_rebuild: false,
  }, {
    // actual task definition here
    type: gb.SINGLE,
    func: doSomething,
  },
});
```
Options
* **`key`** - required cache key
* **`version`** - required cache version - This must be _manually_ incremented when your task's version changes.  The automatic hashing of task functions to detect version changes is unstable across Node.js version and platforms, so cannot be used lest the cache be invalid on any installation other than the one that generated it.
* **`cache_root`** - optional root folder for caching, defaults to `gb.getSourceRoot()/../.gbcache/`
* **`do_cache_write`** optional boolean to enable writing to the cache after every task run, defaults to `false` unless `--cache-write` is passed on the command line.  This is generally not recommended unless you want developers to always commit and updated cache folder with each commit that changes one of the sources (which has increases the chance of meaningless merge conflicts, etc).
* **`do_cache_rebuild`** optional boolean to enable pruning and rebuilding the cache during the first task run, defaults to `false` unless `--cache-rebuild` is passed on the command line.  This should be done only periodically when the cache is significantly out of date and needs to be updated and committed to source control.
* **`gzexts`** optional list of file extensions that should be stored gzipped in the cache


Example usage in build script:
```javascript
const imagemin = require('glov-build-imagemin');
const imageminOptipng = require('imagemin-optipng');

const gbcache = require('glov-build-cache');

gb.task({
  name: 'imagemin',
  input: '*.png',
  ...gbcache({
    key: 'imagemin',
    version: 1,
  }, imagemin({
    plugins: [
      imageminOptipng(),
    ],
  })),
});
```
Example occasional workflow to update cache for the rest of your team or build systems, etc:
```
node build imagemin --cache-rebuild
git add .
git commit -m "update build cache"
```

---
_Source: https://npm.io/package/glov-build-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
