# readthrough

> Read through cache implementation

Latest version **0.1.1** (published 2016-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install readthrough
pnpm add readthrough
yarn add readthrough
bun add readthrough
```

## 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.1.1 |
| Published | 2016-10-27 |
| First published | 2016-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Johan Kanefur |
| Maintainers | zappen999 |
| Keywords | cache, readtrough, redis |

## Links

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

## 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.1.1 (latest) — 2016-10-27
- 0.1.0 — 2016-10-27

## README

# Readthrough
Node.js read-through cache implementation, to be used with any cache engine.

![](https://travis-ci.org/kodjevlar/readthrough.svg?branch=master)
[![codecov](https://codecov.io/gh/kodjevlar/readthrough/branch/master/graph/badge.svg)](https://codecov.io/gh/kodjevlar/readthrough)

## Installation
`npm install readthrough --save`

## Usage

### Setup
```js
const Cache = require('readthrough');

Cache.setup({
  read: function(key) {
    // Your implementation of reading from cache here...
    return Promise.resolve(undefined); // Return undefined on cache misses
  },
  write: function(key, data, ttl) {
    // Your implementation of writing to cache here...
    return Promise.resolve(); // Return promise indicating write result
  },
  enabled: true // Whether or not to enable the readthrough 
});
```

### Readthrough

API:<br/>
`readthrough(entity, identifier, ttl, callback)`

Where `entity` is the name of the entity to get. `identifier` is an object that
identifies the specific entity. `entity` and `identifier` is used to create
the cache key.

`ttl` is the time-to-live value for the entry. `callback` will be executed on
cache misses. Your DB (or whatever) calls goes here.

```js
Cache.readthrough('customer', { id: 1 }, 3600, function() {
  return Promise.resolve({
    name: 'Test',
    email: 'test@test.com'
  });
}).then(function(data) {
  console.log(data); // Actual data, from cache or from your callback
});
```

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