# bedrock-caches

> A collection of cache implementations for NodeJS

Latest version **0.0.4** (published 2016-07-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install bedrock-caches
pnpm add bedrock-caches
yarn add bedrock-caches
bun add bedrock-caches
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2016-07-20 |
| First published | 2016-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sam Vervaeck |
| Maintainers | samvv |
| Keywords | cache, bedrock, library, api |

## Links

- npm: https://www.npmjs.com/package/bedrock-caches
- Repository: https://github.com/BedrockJS/bedrock-caches
- Homepage: https://github.com/BedrockJS/bedrock-caches#readme
- Issues: https://github.com/BedrockJS/bedrock-caches/issues
- npm.io page: https://npm.io/package/bedrock-caches

## 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.0.4 (latest) — 2016-07-20
- 0.0.3 — 2016-07-20
- 0.0.2 — 2016-07-20
- 0.0.1 — 2016-07-20

## README

Bedrock Cache Collection
========================

This is a collection of cache implementations for use in your application, e.g.
for caching template data. Modules are seperated into several files so only the
things you need get loaded.

A list of cache implementations:

 - In-memory cache
 - JSON object file cache
 - Cache wrapper for dynamic values

## API

Caches implement the [Cache&lt;K, V&gt; interface](https://github.com/BedrockJS/bedrock-caches/blob/master/interfaces.d.ts),
which makes it easy to implement your own caches.

Almost all caches have a constructor in the form of:

```
new Cache(options)
```

Where the options object contains the following keys:

 - **fetch**: function that will be used to fetch a value if the value was not found in the cache

The following methods are available on all caches:

#### cache.get(key)

Get the value associated with `key`, doing a _fetch_ if the value was not found.

#### cache.hasCached(key)

Checks if the value is added to the local cache.

#### cache.fetch(key)

Does a direct fetch for the given key. The value is not stored in the cache.

#### cache.evict(key)

Removes the value stored at `key` from the cache. Will not report an error if no values were found.

#### new MemoryCache(options)

Creates a new cache that will store values in-memory.

```ts
import { MemoryCache } from "bedrock-caches/lib/memory"
```

### new JSONFileCache(options)

Creates a new cache that serializes values onto disk.

 - **cacheDir** the directory to store the serialized objects

```ts
import { JSONFileCache } from "bedrock-caches/lib/json"
```

### new UpdateCache(parentCache)

Creates a new cache that will listen to the `change`-event of its values and
re-fetch as appropriate. The `parentCache` is used to store the values in.

```ts
import { UpdateCache } from "bedrock-caches/lib/update"
```

## Limitations

 - Currently only supports synchronous caching

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