# zoo-cache

> Universal caching solution

Latest version **0.0.8** (published 2014-08-26) · MIT license · 0 weekly downloads

## Install

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

## 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.0.8 |
| Published | 2014-08-26 |
| First published | 2014-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ruleechen |
| Maintainers | jszoo |
| Keywords | zoo, cache, caching, jszoo |

## Links

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

## Dependencies (1)

- [zoo-utils](https://npm.io/package/zoo-utils.md) 0.0.8

## 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.8 (latest) — 2014-08-26
- 0.0.7 — 2014-08-21
- 0.0.6 — 2014-08-21
- 0.0.5 — 2014-08-08
- 0.0.4 — 2014-08-08
- 0.0.3 — 2014-08-08
- 0.0.2 — 2014-08-07
- 0.0.1 — 2014-08-06

## README

zoo-cache
=========

Universal caching solution

Features
---------
+ Customizable inner data store
+ Customizable inner data region
+ Support cache item expire and expire callback
+ Events on operating cache item

Installation
-------------

```shell
$ npm install zoo-cache
```

Data store
-----------
Store is the inner core data storage. We can implement it to store data in memory or database etc. There is already a **MemoryStore** builtin in this solution. Will use MemoryStore when user doesn't specified the store option.

```javascript
var cache = require('zoo-cache');
// change default store
cache.defaultStore(new MongoStore());
```

Data region
------------
Region is a subset of the data store. 

```javascript
var cache = require('zoo-cache');
// animals set
var animals = cache.region('animals');
// or specified a store
var animals = cache.region('animals', new MongoStore());
```

API
---------------
Friendly and simply api.

```javascript
var cache = require('zoo-cache');
// animals set
var animals = cache.region('animals');
// api list
animals.sto(); // get or set inner store of current region
animals.set('cat', 'cat-mvc');
animals.get('cat');
animals.remove('cat');
animals.exists('cat');
animals.all();
animals.count();
animals.clear();
```

Caching expire
---------------
User can specify a absolute expire date to cache item and a expire callback also available.

```javascript
// full api
animals.set(key, val, expire, notify);
// example
animals.set('cat', 'cat-mvc', new Date(), function(param) {
    console.log(param.value + ' is ' + param.action);
});
```

Store events
-------
All data changes events of the inner data store.

```javascript
var store = animals.sto();
store.on('set', function(param) { /* param.region, param.key, param.value */ });
store.on('remove', function(param) { /* param.region, param.key */ });
store.on('clear', function(param) { /* param.region */ });
```

Tests
-------------

```shell
$ npm install
$ npm test
```

License
--------

[MIT](LICENSE)

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