# cache

> Simple caching object with optional TTL and file system persistence.

Latest version **3.0.0** (published 2022-06-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install cache
pnpm add cache
yarn add cache
bun add 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 | 3.0.0 |
| Published | 2022-06-26 |
| First published | 2011-10-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joe Hitchens |
| Maintainers | sleeplessinc |

## Links

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

## Dependencies (1)

- [ds](https://npm.io/package/ds.md) ^1.4.2

## Recent versions

- 3.0.0 (latest) — 2022-06-26
- 2.3.1 — 2020-03-30
- 2.3.0 — 2020-03-30
- 2.2.0 — 2020-03-30
- 2.1.0 — 2017-12-19
- 2.0.0 — 2017-12-19
- 1.1.2 — 2013-10-17
- 1.0.1 — 2011-10-13
- 1.0.0 — 2011-10-13

## README

# Cache - A simple caching object with TTL

Copyright 2017 Sleepless Software Inc. All rights reserved.


## Install

	npm install cache


## Usage

	Cache = require("cache");

	c = new Cache(10 * 1000);    // Create a cache with 10 second TTL

	key = "foo";
	val = "something";    // any object

	c.put(key, val);      // put it in the cache.
	                      // Optional 3rd arg is TTL for just this
						  // key, e.g.;  c.put(key, val, 5 * 1000);

	c.get(key);           // "something" (less than 10 secs have passed)

	// 11 seconds later ...
	setTimeout(function() {

		c.get(key);       // expired out of cache

	}, 11 * 1000);


## More

You can also do some other stuff.

	c.del(key)            // delete key/val before expiry

You can create a cache that will write its contents to a file in
JSON form (not recommended for production purposes):

	c = new Cache(10 * 1000, "data.json");

Now, when do anything that changes the contents of the cache,
it will write it to the file "data.json":

	c.put(key, val);		// data.json appears

Also, the cache will be preloaded from the file when you
instantiate it, if the file is present.

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