# cachew

> Lightweight local caching primitives for Node.js

Latest version **0.1.1** (published 2015-08-12) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2015-08-12 |
| First published | 2014-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kevin "Schmidty" Smith |
| Maintainers | shenanigans |
| Keywords | memory, in-memory, cache, store, range, search, index |

## Links

- npm: https://www.npmjs.com/package/cachew
- Homepage: https://github.com/shenanigans/node-exhibition
- Issues: https://github.com/shenanigans/node-exhibition/issues
- npm.io page: https://npm.io/package/cachew

## 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) — 2015-08-12
- 0.0.1 (beta) — 2014-08-13
- 0.1.0 — 2015-01-17

## README

node-cachew
===========
In-memory value caching for expiring keys and an efficient range index.


Installation And Use
--------------------
```shell
$ npm install cachew
```

#####ChainCache
Useful for simple refs expiring on a uniform timeout. Uses a linked-list configuration.
```javascript
var example = new require('cachew').ChainCache (
    100000,         // maximum key count
    1000 * 60 * 5,  // store for five minutes
    true            // renew keys when read
);
http.createServer (function (request, response) {
    // cache whole requests by ip
    example.set (
        request.connection.remoteAddress,
        request
    );

    // process request
});
```

#####DocumentChainCache
Used for complex Object refs which must be indexed on more than one key. Basically a ChainCache
under the hood.
```javascript
var example = new require('cachew').DocumentChainCache (
    [ 'remoteAddress' ],
    100000,         // maximum key count
    1000 * 60 * 5,  // store for five minutes
    true            // renew keys when read
);
http.createServer (function (request, response) {
    // cache connection information by ip
    example.set (request.connection);

    // process request
});
```

#####RangeIndex
When you need to store and retrieve values by numerical fit, use a RangeIndex.
```javascript
var example = new require('cachew').RangeIndex (
    100000 // maximum key count
);
var points = [
    { x:10,     y:15.3,     data:payload_01},
    { x:4.81,   y:7,        data:payload_02},
    { x:100,    y:153,      data:payload_03},
]
for (var i in points) {
    // map points by distance from the origin
    var point = points[i];
    var distance = Math.sqrt(
        Math.pow (point.x, 2)
      + Math.pow (point.y, 2)
    );
    example.set (distance, point);
}

// select all points within a hollow circle
// centered on the origin
console.log (example.getRange (10, 30));
```


Development
-----------
`cachew` is developed and maintained by Kevin "Schmidty" Smith under the MIT license. If you want to
see continued development, please help me
[pay my bills!](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=PN6C2AZTS2FP8&lc=US&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted)


LICENSE
-------
The MIT License (MIT)

Copyright (c) 2015 Kevin "Schmidty" Smith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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