# async-disk-cache

> Async disk cache

Latest version **2.1.0** (published 2020-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-disk-cache
pnpm add async-disk-cache
yarn add async-disk-cache
bun add async-disk-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.0 |
| Published | 2020-06-24 |
| First published | 2015-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 8.* \|\| >= 10.* |
| Dependencies | 7 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Stefan Penner |
| Maintainers | rwjblue, stefanpenner, trentmwillis |
| Keywords | cache, temp, file |

## Links

- npm: https://www.npmjs.com/package/async-disk-cache
- Repository: https://github.com/stefanpenner/async-disk-cache
- Homepage: https://github.com/stefanpenner/async-disk-cache#readme
- Issues: https://github.com/stefanpenner/async-disk-cache/issues
- npm.io page: https://npm.io/package/async-disk-cache

## Dependencies (7)

- [rsvp](https://npm.io/package/rsvp.md) ^4.8.5
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.0
- [heimdalljs](https://npm.io/package/heimdalljs.md) ^0.2.3
- [username-sync](https://npm.io/package/username-sync.md) ^1.0.2
- [istextorbinary](https://npm.io/package/istextorbinary.md) ^2.5.1

## 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.0 (latest) — 2020-06-24
- 2.0.0 — 2019-10-30
- 1.3.5 — 2019-10-30
- 1.3.4 — 2019-02-07
- 1.3.3 — 2017-09-21
- 1.3.2 — 2017-05-15
- 1.3.1 — 2017-04-04
- 1.3.0 — 2017-04-04
- 1.2.3 — 2017-04-03
- 1.2.2 — 2017-03-16
- 1.2.1 — 2017-03-10
- 1.2.0 — 2017-03-10
- 1.1.1 — 2017-03-10
- 1.1.0 — 2017-03-10
- 1.0.9 — 2016-10-29
- … 10 more at https://npm.io/package/async-disk-cache/versions

## README

# async-disk-cache [![Build status](https://ci.appveyor.com/api/projects/status/lfliompah66m611x?svg=true)](https://ci.appveyor.com/project/embercli/async-disk-cache) [![Build Status](https://travis-ci.org/stefanpenner/async-disk-cache.svg)](https://travis-ci.org/stefanpenner/async-disk-cache) 

An async disk cache. inspired by [jgable/cache-swap](https://github.com/jgable/cache-swap)

A sync sibling version is also available: [stefanpenner/sync-disk-cache](https://github.com/stefanpenner/sync-disk-cache/)

By default, this will usge `TMPDIR/<username>/` for storage, but this can be changed by setting the `$TMPDIR` environment variable.

## Example

```js
var Cache = require('async-disk-cache');
var cache = new Cache('my-cache');
// 'my-cache' also serves as the global key for the cache.
// if you have multiple programs with this same `cache-key` they will share the
// same backing store. This by design.

// checking
cache.has('foo').then(function(wasFooFound) {

});

// retrieving (cache hit)
cache.get('foo').then(function(cacheEntry) {
  cacheEntry === {
    isCached: true,
    key: 'foo',
    value: 'content of foo'
  }
});

// retrieving (cache miss)
cache.get('foo').then(function(cacheEntry) {
  cacheEntry === {
    isCached: false,
    key: 'foo',
    value: undefined
  }
});

// setting
cache.set('foo', 'content of foo').then(function() {
  // foo was set
});

// clearing one entry from the cache
cache.remove('foo').then(function() {
  // foo was removed
})

// clearing the whole cache
cache.clear().then(function() {
  // cache was cleared
})
```

Enable compression:

```js
var Cache = require('async-disk-cache');
var cache = new Cache('my-cache', {
  compression: 'gzip' | 'deflate' | 'deflateRaw', // basically just what nodes zlib's ships with
  supportBuffer: 'true' | 'false' // add support for file caching (default `false`)
})
```

## HELP!...my TMP dir is growing unbounded!

### description
In general most OS distributions come with cron like tasks, which purge unused files in `$TMPDIR`. For example, ubuntu typically uses `tmpreaper` and macOS uses various tasks in `/etc/periodic/*`.

## options

If your OS distribution does not provide such a cleanup mechanism:

a) We stronglly recommend utilizing one, as other sync-disk-cache is not alone in rely on this behavior
b) If that is not possible, we recommend changing your `$TMPDIR` to something project specific and manually purging it.

## License

Licensed under the MIT License, Copyright 2015 Stefan Penner

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