1 | # Route-Cache
|
2 | Simple 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 |
|
8 | Make 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
|
17 | npm install route-cache
|
18 | ```
|
19 |
|
20 | ## Test
|
21 | ```sh
|
22 | npm test
|
23 | ```
|
24 |
|
25 | ## How to use
|
26 | ```javascript
|
27 |
|
28 | var routeCache = require('route-cache');
|
29 |
|
30 | // cache route for 20 seconds
|
31 | app.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
|
42 | routeCache.removeCache('/index');
|
43 | ```
|
44 |
|
45 | ## Future plans / todos
|
46 | - client-side Cache-Control
|
47 | - support for distributed caches (redis or memcache)
|
48 |
|
49 | ------
|
50 | The MIT License (MIT)
|
51 |
|
52 | Copyright (c) 2014 Brad Oyler
|
53 |
|
54 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
55 | of this software and associated documentation files (the "Software"), to deal
|
56 | in the Software without restriction, including without limitation the rights
|
57 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
58 | copies of the Software, and to permit persons to whom the Software is
|
59 | furnished to do so, subject to the following conditions:
|
60 |
|
61 | The above copyright notice and this permission notice shall be included in all
|
62 | copies or substantial portions of the Software.
|
63 |
|
64 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
65 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
66 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
67 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
68 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
69 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
70 | SOFTWARE.
|
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
|