# plain-cache

> Plain simple, in-memory, tiny-in-size JavaScript cache library

Latest version **1.1.12** (published 2017-10-17) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.12 |
| Published | 2017-10-17 |
| First published | 2017-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tan Nhu |
| Maintainers | tnhu |
| Keywords | cache, plain cache, caching, simple cache |

## Links

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

## 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

- 1.1.12 (latest) — 2017-10-17
- 1.1.11 — 2017-10-14
- 1.1.10 — 2017-10-14
- 1.1.9 — 2017-10-14
- 1.1.8 — 2017-10-14
- 1.1.7 — 2017-07-31
- 1.1.5 — 2017-07-30
- 1.1.4 — 2017-07-30
- 1.1.3 — 2017-07-30
- 1.1.2 — 2017-07-30
- 1.1.1 — 2017-07-30
- 1.1.0 — 2017-07-30
- 1.0.1 — 2017-07-29
- 1.0.0 — 2017-07-28

## README

## plain-cache

Plain-simple, in-memory, tiny-in-size (less than 500 bytes when minified + gzipped) cache library, runs on both browser and NodeJS environments.

### Install

`npm i --save plain-cache`

### Samples

```javascript
const cache = require('plain-cache')
```

or

```javascript
import cache from 'plain-cache'
```

```javascript
// Set cache with key = `foo`, value = `bar`, expired in 3 seconds
cache.set('foo', 'bar', 3000)

// Get back cache with key `foo`
cache.get('foo') // === 'bar'

// get() accepts default value and ttl
cache.get('foo', 'bar') // if cache with key = `foo` not found, set it to `bar`

// get() also accepts ttl
cache.get('foo', 'bar', 3000)

// Delete cache with key `foo`
cache.del('foo')

// Clear cache (everything is removed)
cache.clear()
```

`plain-cache` has some convenient timing TTL constants.

```javascript
cache.VALID_FOR_10_SECONDS
cache.VALID_FOR_30_SECONDS
cache.VALID_FOR_A_MINUTE
cache.VALID_FOR_5_MINUTES
cache.VALID_FOR_10_MINUTES
cache.VALID_FOR_30_MINUTES
cache.VALID_FOR_AN_HOUR
cache.VALID_FOR_A_DAY
cache.VALID_FOR_A_WEEK
cache.VALID_FOR_30_DAYS
cache.VALID_FOREVER
```

### Test

To run unit tests locally:

`npm test`

### License

MIT

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