Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stutrek/node-debounced-io
A very simple in memory http cache that begins when the request enters the system.
https://github.com/stutrek/node-debounced-io
Last synced: about 1 month ago
JSON representation
A very simple in memory http cache that begins when the request enters the system.
- Host: GitHub
- URL: https://github.com/stutrek/node-debounced-io
- Owner: stutrek
- Created: 2013-05-25T03:16:36.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-06-18T16:52:31.000Z (over 11 years ago)
- Last Synced: 2024-04-17T09:25:31.126Z (7 months ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-debounced-io
Some io operations are guaranteed to return the same result. Having more than one of these in progress at any one time serves no purpose. This allows you to create an http server that will cache the result of a request until the request finishes, or for a set time period.
## Basic Usage
It works just like a normal node http server except you create it with a config callback in addition to a request callback.
```javascript
var http = require('node-debounced-io/http');function configCallback( req, config ) {
// config.key === req.url;
// config.maxAge === 0; // ms
// config.minAge === 0; // ms
// config.keepGenerated === false;
}function requestCallback( req, res ) {
// your web server code
}http.createServer( requestCallback, configCallback ).listen(8000);
```
## Config Options
The configCallback is called on every request. It is passed a request object and a config object, already populated with defaults. Override what you please.
* `config.key` - the cache key for this request. Defaults to the url, but cookes can be added.
* `config.maxAge` - the cache will be cleared this long after the request completes.
* `config.keepGenerated` - If this is true it will try to maintain a copy of this in the cache.
* `config.minAge` - If keepGenerated is true it will start generating a new copy after this amount of time.