# cache-swap

> A simple temp file based swap for speeding up operations

Latest version **0.3.0** (published 2016-11-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2016-11-04 |
| First published | 2013-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jacob Gable |
| Maintainers | jgable, shinnn |
| Keywords | cache, swap, temp, file |

## Links

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

## Dependencies (4)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [rimraf](https://npm.io/package/rimraf.md) ^2.4.0
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.2
- [object-assign](https://npm.io/package/object-assign.md) ^4.0.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

- 0.3.0 (latest) — 2016-11-04
- 0.2.3 — 2015-09-11
- 0.2.2 — 2015-08-10
- 0.2.1 — 2015-06-09
- 0.2.0 — 2015-02-21
- 0.1.1 — 2015-01-09
- 0.1.0 — 2014-10-03
- 0.0.6 — 2014-02-19
- 0.0.5 — 2013-12-27
- 0.0.4 — 2013-08-19
- 0.0.3 — 2013-04-18
- 0.0.2 — 2013-04-11
- 0.0.1 — 2013-03-26

## README

# cache-swap

[![NPM version](http://img.shields.io/npm/v/cache-swap.svg)](https://www.npmjs.com/package/cache-swap)
[![Build status](https://ci.appveyor.com/api/projects/status/98uvrob6ogl7noey?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/cache-swap)
[![Dependency Status](https://img.shields.io/david/jgable/cache-swap.svg?label=deps)](https://david-dm.org/jgable/cache-swap)
[![devDependency Status](https://img.shields.io/david/dev/jgable/cache-swap.svg?label=devDeps)](https://david-dm.org/jgable/cache-swap#info=devDependencies)

A lightweight file swap cache backed by temp files.

## Example

```javascript
var swap = new CacheSwap({
    cacheDirName: "HoganizeSwap"
  }),
  processTemplate = function(template, done) {
    var templateStr = template.content,
      templatePath = template.path,
      templateHash = files.shaIt(templateStr);

    swap.getCached("hoganize", templateHash, function(err, cached) {
      if(err) {
        return done(err);
      }

      var yeahbrotha,
        stringed;

      if(cached) {
        yeahbrotha = cached.contents;
        try {
          addToHoganized(yeahbrotha, templatePath);
        } catch(e){
          return done(e);
        }

        done();
      } else {
        yeahbrotha = self._compileTemplate(templateStr, templatePath);
        // Add the compiled template to the cache swap for next time.
        swap.addCached("hoganize", templateHash, yeahbrotha, function(err) {
          if(err) {
            return done(err);
          }

          try {
            addToHoganized(yeahbrotha, templatePath);
          } catch(e) {
            return done(e);
          }

          done();
        });
      }

    });
  };
```

## License

Licensed under the MIT License, Copyright 2013-2015 Jacob Gable

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