# transparentcache

> flexible transparent caching layer for object methods and functions with versatile storing strategies

Latest version **1.0.0** (published 2014-09-27) · 0 weekly downloads

## Install

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

## 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 | 1.0.0 |
| Published | 2014-09-27 |
| First published | 2013-06-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Manuel Ernst |
| Maintainers | zaphod1984 |
| Keywords | cachinglayer, transparent cache, memoize, cache, lru, transparent |

## Links

- npm: https://www.npmjs.com/package/transparentcache
- Repository: https://github.com/zaphod1984/node-transparentCache
- Issues: https://github.com/zaphod1984/node-transparentCache/issues
- npm.io page: https://npm.io/package/transparentcache

## Dependencies (2)

- [sigmund](https://npm.io/package/sigmund.md) ^1.0.0
- [lru-cache](https://npm.io/package/lru-cache.md) ^2.5.0

## 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.0.0 (latest) — 2014-09-27
- 0.4.2 — 2014-05-21
- 0.4.1 — 2013-11-05
- 0.4.0 — 2013-07-09
- 0.3.3 — 2013-06-26
- 0.3.2 — 2013-06-25
- 0.3.1 — 2013-06-25
- 0.2.4 — 2013-06-25
- 0.2.3 — 2013-06-25
- 0.2.2 — 2013-06-24
- 0.2.1 — 2013-06-24
- 0.2.0 — 2013-06-24

## README

# node-transparentCache [![Build Status](https://travis-ci.org/zaphod1984/node-transparentCache.png)](https://travis-ci.org/zaphod1984/node-transparentCache)

[![NPM](https://nodei.co/npm/transparentcache.png)](https://nodei.co/npm/transparentcache/)

[![NPM](https://nodei.co/npm-dl/transparentcache.png?months=3)](https://nodei.co/npm/transparentcache/)

## Installation

````bash
$ npm install transparentcache
````

## transparentcache(client, [options])

transparentcache exposes one single function that can be used to cache the output of object members or the output of single function.
It follows the memoize pattern and accepts a configuration that specifies which parameters are acutally relevant for the reidentification of a cache member.

### options (object)

* `cachingStrategy` specifies the strategy that is used to cache the method output, see "Strategies" below. (default: Plain)
* `methods` a hash which keys are the names of the methods to cache, its values are pointing to the index of the parameters that are relevant for the cache name. e.g. `{foo:[0]}` specifies that the function `foo` should be cached and that only the first parameter should be considered for caching.

### options (function)

* `cachingStrategy` specifies the strategy that is used to cache the method output, see "Strategies" below. (default: Plain)
* `parameters` an array that specifies which function parameters are responsible for the caching. e.g. `[0]` states that only the first argument should be considered for the cache identifcation name

## Examples

For more detailed examples check the `examples` folder where examples for the caching of asynchronous object members, synchronous object members and asynchronous functions are located.

### Sync Caching

```javascript
var cachify = require('../');

function one (a, b) {
    console.log( 'one actually invoked' );
    return '|' + b + '|' + a + '|' + b + '|';
}

var oneCached = cachify(one, {parameters:[0]});

console.log( oneCached(1, 2) );
console.log( oneCached(1, 3) );
console.log( oneCached(1, 4) );
console.log( oneCached(1, 5) );
console.log( oneCached(2, 2) );
console.log( oneCached(2, 999) );
```

yields the following output:
```
one actually invoked
|2|1|2|
|2|1|2|
|2|1|2|
|2|1|2|
one actually invoked
|2|2|2|
|2|2|2|
```

## Cachingstrategies

Cachingstrategies are responsible to implement the way in that the cache values are stored.

### Creation

Strategies can be created by either doing it by hand:
```javascript
var strategy = new cachify.strategies.Plain();
```

or using the factory method:
```javascript
var strategy = cachify.createStrategy('Plain');
```

A second optional constuctor parameter can be assigned to specify the the configuration of the caching strategy.

### Strategies

Four strategies are built-in:
* Plain: Simple key-value storage
* RingBuffer: Stores a finite number and kicks out the first inserted, accepts an additional options object that specifies the size. Accepts the parameter `size` (default: 10)
* Lru: Stores a finit number and kicks out the last recently used, accepts an additional options object that specifies the size. Accepts the parameter `size` (default: 10).
* Timeout: Stores cache values for a defined span of time. Accepts the parameter `ttl` which is the lifetime of a cache object in milliseconds. (default: 5 minutes)

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