# sync-disk-cache

> sync disk cache

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

## Install

```sh
npm install sync-disk-cache
pnpm add sync-disk-cache
yarn add sync-disk-cache
bun add sync-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-06-04 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 8.* \|\| >= 10.* |
| Dependencies | 5 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Stefan Penner |
| Maintainers | rwjblue, stefanpenner, trentmwillis |
| Keywords | cache, temp, file |

## Links

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

## Dependencies (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.6
- [username-sync](https://npm.io/package/username-sync.md) ^1.0.2

## 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.4 — 2019-10-30
- 1.3.3 — 2019-02-07
- 1.3.2 — 2017-05-15
- 1.3.1 — 2017-04-04
- 1.3.0 — 2017-04-04
- 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.1 — 2015-06-04
- 1.0.0 — 2015-06-04
- 0.0.2 — 2015-06-04
- … 1 more at https://npm.io/package/sync-disk-cache/versions

## README

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

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

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

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

All stored values become strings.

## Example

```js
var Cache = require('sync-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') === wasFooFound;

// retrieving (cache hit)
cache.get('foo') === {
  isCached: true,
  path: 'foo',
  content: 'content of foo'
}

// retrieving (cache miss)
cache.get('foo') === {
  isCached: false,
  path: 'foo',
  content: undefined
}

// retrieving (cache miss)
cache.set('foo', 'content of foo'); // was set

// remove a key
cache.remove('foo');

// clearing the cache
cache.clear(); // cache was cleared
```


Enable compression:

note: node 0.10.x does not support the synchronous zlib method variants, so compression is only available > 0.10.x

```js
var Cache = require('sync-disk-cache');
var cache = new Cache('my-cache', {
  compression: 'gzip' | 'deflate' | 'deflateRaw' // basically just what nodes zlib's ships with
})
```

## 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/sync-disk-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
