# cache-client

> An easy to use cache client that allows use for memcached, redis, or lru-cache

Latest version **0.0.22** (published 2014-04-16) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.22 |
| Published | 2014-04-16 |
| First published | 2014-04-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Chris Weston |
| Maintainers | notsew |
| Keywords | redis, memcached, cache, lru-cache |

## Links

- npm: https://www.npmjs.com/package/cache-client
- Repository: https://github.com/Notsew/cache-client
- Issues: https://github.com/Notsew/cache-client/issues
- npm.io page: https://npm.io/package/cache-client

## Dependencies (3)

- [redis](https://npm.io/package/redis.md) *
- [lru-cache](https://npm.io/package/lru-cache.md) *
- [memcached](https://npm.io/package/memcached.md) *

## 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.22 (latest) — 2014-04-16
- 0.0.21 — 2014-04-11
- 0.0.20 — 2014-04-10
- 0.0.19 — 2014-04-10
- 0.0.18 — 2014-04-10
- 0.0.17 — 2014-04-10
- 0.0.16 — 2014-04-10
- 0.0.15 — 2014-04-09
- 0.0.14 — 2014-04-09
- 0.0.13 — 2014-04-09
- 0.0.12 — 2014-04-09
- 0.0.11 — 2014-04-09
- 0.0.10 — 2014-04-09
- 0.0.9 — 2014-04-09
- 0.0.8 — 2014-04-09
- … 7 more at https://npm.io/package/cache-client/versions

## README

# cache-client
This is a caching api that allows you to connect to redis, memcached, or lru-cache.  This utilizes the npm modules lru-cache, redis, or memcached.  I have required them as dependencies so that they are installed with cache-client.

I started this project so that I could have an easy way to interact with each cache mechanism, using a single api.  This made it easy to use between multiple environments and multiple projects.
Now Supports all three cache stores.
Added TTL support for Redis and Memcached, and LRU-cache.

The TTL for LRU is a bit experimental, I haven't tested it yet with the other lru-cache options.

Added in prefix support:  config.prefix = "your_prefix_here"; will prefix all keys no matter the store.

## Initialization
```javascript
config = {store: "redis", port:6379, host:"127.0.0.1", opts:{}, auth:"password"};
config = {store: "memory", opts:{}};
config = {store: "memcached", host:"localhost:11211", opts:{}};
var cacheClient = require("cache-client");
cacheClient.setup(config);

```

## Usage
Normal Methods
```javascript
cacheClient.read("foo", function(result)
{
	//do something here
});

cacheClient.write("foo", "bar");
```
Advanced Methods
You have access to the underlying modules(redis,memcached, lru) by calling cacheClient.client.method();
```javascript
cacheClient.client.keys();
cacheClient.client.values();

cacheClient.client.some_redis_method();
cacheClient.client.some_memcached_method();
```


## API

* ` write(key,value,ttl) if ttl is not provided, then it will default to 0, which will cache the item until it is cleared.`

* ` read(key, callback(result))`

* ` remove(key)`

* ` clear() -> must be careful with this, this will flush the entire cache, so if you are using the same store for both sessions and cache or multiple apps use the same store, this will clear everything.`

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