# simple-request-caching

> A very simple caching approach for requests.

Latest version **0.0.8** (published 2016-08-07) · VOL license · 0 weekly downloads

## Install

```sh
npm install simple-request-caching
pnpm add simple-request-caching
yarn add simple-request-caching
bun add simple-request-caching
```

## 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 | 2016-08-07 |
| First published | 2015-02-17 |
| Weekly downloads | 0 |
| License | VOL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | saibotsivad |
| Maintainers | saibotsivad, npmupdater |
| Keywords | cache, caching |

## Links

- npm: https://www.npmjs.com/package/simple-request-caching
- Repository: https://github.com/saibotsivad/simple-request-caching
- Issues: https://github.com/saibotsivad/simple-request-caching/issues
- npm.io page: https://npm.io/package/simple-request-caching

## 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) — 2016-08-07
- 0.0.7 — 2015-02-17
- 0.0.6 — 2015-02-17
- 0.0.5 — 2015-02-17

## README

# simple-request-caching [![Build Status](https://travis-ci.org/tobiaslabs/simple-request-caching.svg?branch=master)](https://travis-ci.org/tobiaslabs/simple-request-caching)

A very simple caching approach for requests.

## install

There are no external dependencies for the code, so feel free to copy+paste it into whatever framework
you are using (e.g., [here's an Angular example](https://gist.github.com/saibotsivad/84d8faf3c8351c89ea3b)).
Otherwise, install using:

```sh
npm install simple-request-caching
```

## using

The basic setup is this:

```js
var CachedRequest = require('simple-request-caching')

var request = new CachedRequest({
	cacheMillis: 500, // the millis that the request is cached, or -1 for forever
	request: function(params) {
		return http.get('/url/path', params)
	}
})
```

Set a single one of those up for any request you want to cache, then use it like:

```js
request({ key: 'value' }).then(function(data) {
	// the response from the http.get(), as a promise
})
```

## api

When you make a new `CachedRequest`, it has the following parameters:

* `cacheMillis` (required): The number of milliseconds to cache the request
	response. Use `-1` to cache things forever.
* `request` (required): The function called when a request is not cached. Must
	return a promise. Rejected promises are not cached.
* `stringify` (optional): A function that is called to stringify the request
	parameters. If unspecified, a default is used which will stringify flat
	object correctly and efficiently. If you have deeper objects, you'll want
	to implement your own `stringify` function.

## license

[VOL](http://veryopenlicense.com)

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