UNPKG

2.36 kBMarkdownView Raw
1# Route-Cache
2Simple middleware for Express route caching with a given TTL (in seconds)
3
4[![Build Status](https://travis-ci.org/bradoyler/route-cache.svg?branch=master)](https://travis-ci.org/bradoyler/route-cache)
5[![NPM Version][npm-image]][npm-url]
6[![Downloads][downloads-image]][npm-url]
7
8Make your routes do this ->![dodging](http://forgifs.com/gallery/d/80400-8/Muhammad-Ali-dodges-punches.gif)
9
10## Why?
11- makes hard-working routes super-fast, under heavy-load
12- easy to use and fork for your needs
13- works with gzip compression
14
15## Install
16```sh
17npm install route-cache
18```
19
20## Test
21```sh
22npm test
23```
24
25## How to use
26```javascript
27
28var routeCache = require('route-cache');
29
30// cache route for 20 seconds
31app.get('/index', routeCache.cacheSeconds(20), function(req, res){
32 // do your dirty work here...
33 console.log('you will only see this every 20 seconds.');
34 res.send('this response will be cached');
35});
36
37
38```
39
40## Delete a cached route
41```javascript
42routeCache.removeCache('/index');
43```
44
45## Future plans / todos
46- client-side Cache-Control
47- support for distributed caches (redis or memcache)
48
49------
50The MIT License (MIT)
51
52Copyright (c) 2014 Brad Oyler
53
54Permission is hereby granted, free of charge, to any person obtaining a copy
55of this software and associated documentation files (the "Software"), to deal
56in the Software without restriction, including without limitation the rights
57to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
58copies of the Software, and to permit persons to whom the Software is
59furnished to do so, subject to the following conditions:
60
61The above copyright notice and this permission notice shall be included in all
62copies or substantial portions of the Software.
63
64THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
65IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
67AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
68LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
69OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
70SOFTWARE.
71
72[npm-image]: https://img.shields.io/npm/v/route-cache.svg
73[downloads-image]: http://img.shields.io/npm/dm/route-cache.svg
74[npm-url]: https://npmjs.org/package/route-cache