# duo-cache

> The cache duo uses internally

Latest version **2.1.2** (published 2015-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install duo-cache
pnpm add duo-cache
yarn add duo-cache
bun add duo-cache
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2015-07-10 |
| First published | 2015-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Dominic Barnes |
| Maintainers | dominicbarnes |
| Keywords | duo, cache |

## Links

- npm: https://www.npmjs.com/package/duo-cache
- Repository: https://github.com/duojs/cache
- Issues: https://github.com/duojs/cache/issues
- npm.io page: https://npm.io/package/duo-cache

## Dependencies (7)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [level](https://npm.io/package/level.md) ^1.2.0
- [unyield](https://npm.io/package/unyield.md) 0.0.1
- [co-level](https://npm.io/package/co-level.md) ^1.0.1
- [mkdirp-then](https://npm.io/package/mkdirp-then.md) ^1.0.1
- [rimraf-then](https://npm.io/package/rimraf-then.md) ^1.0.0
- [object-values](https://npm.io/package/object-values.md) ^1.0.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2015-07-10
- 2.1.1 — 2015-07-10
- 2.1.0 — 2015-07-10
- 2.0.3 — 2015-07-03
- 2.0.2 — 2015-07-03
- 2.0.1 — 2015-07-03
- 2.0.0 — 2015-07-03

## README

# duo-cache

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]

> The cache duo uses internally during builds.

## API

This cache uses [LevelDB](https://github.com/google/leveldb)
internally (via [level](https://www.npmjs.com/package/level)).
The idea behind this cache is to help speed up duo's builds by
storing data on disk so it can be read quickly later.

### Cache(location)

The `location` refers to the destination of the LevelDB database directory.

### Cache#read()

Reads the all the stored files from the database into memory.

### Cache#update(mapping)

Accepts the updated in-memory `mapping` and saves all the files into cache.

### Cache#file(id, [data])

Can be used to set/get a single file's data from the cache. If `data` is
excluded, it is assumed to be a getter. (otherwise, it will be a setter)

### Cache#plugin(name, key, [data])

Can be used to set/get a plugin's cache data. If `data` is excluded, it
is assumed to be a getter. (otherwise, it will be a setter)

The `name` should be the same as the plugin's name, to make debugging easier.
The `key` can be either a `String` or an `Array`. Below is a sample plugin
that is using caching.

```js
// hash the source code as well as options to allow this
// to work even if the user changes their config!
var key = [ hash(src), hash(options) ];

// see if it's already been cached
var cached = yield cache.plugin('plugin', key); // get
if (cached) return cached;

// run the normal transformation
var results = plugin(src, options);
// cache the results for next time
yield cache.plugin('plugin', key, results); // set
return results;
```

### Cache#clean()

Closes the database and wipes it out from the disk.


## Roadmap

Currently, this implementation only satisfies the bare-minimum based on
duo's current cache implementation. (currently called the "mapping")

Now that there is a robust data-store in place, more features will be added,
including:

 - give plugins a way to get/set cache data (so they can reduce the amount
   of processing they do on repeated builds)
 - store additional processing during the build process (such as the result
   of scanning a file for dependencies)
 - expose this hook to other modules that cache results (eg: gh-resolve)


[npm-image]: https://img.shields.io/npm/v/duo-cache.svg?style=flat
[npm-url]: https://npmjs.org/package/duo-cache
[travis-image]: https://img.shields.io/travis/duojs/cache.svg?style=flat
[travis-url]: https://travis-ci.org/duojs/cache

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