lru-send
Version:
LRU-based caching middleware for Node.js
71 lines (47 loc) • 1.46 kB
Markdown
<div align="center">
[![npm][npm-img]][npm-url] [![GitHub Workflow Status][actions-badge]][github-actions] [![Coverage][cov-img]][cov-url]
</div>
LRU-based caching middleware for Node.js that patches `res.send`.
- 😲 [**~336x faster**](bench) for heavy operations
- ⚡ ESM-only
- ✨ types out of the box
- 🟥 (optionally) supports [Redis](http://redis.io/)
```sh
pnpm i lru-send
```
```ts
import { lruSend } from 'lru-send'
import { App } from '@tinyhttp/app'
const app = new App()
app.use(lruSend())
app.use('/', (_req, res) => {
someUltraHeavyOp()
res.send('hello')
})
app.listen(3000)
```
```ts
import { lruSend } from 'lru-send/redis'
import { App } from '@tinyhttp/app'
import Redis from 'ioredis'
const redis = new Redis()
const app = new App()
app.use(lruSend(redis))
app.use('/', (_req, res) => {
someUltraHeavyOp()
res.send('hello')
})
app.listen(3000)
```
[]: https://npmjs.com/package/lru-send
[]: https://github.com/tinyhttp/lru-send/actions
[]: https://img.shields.io/coveralls/github/tinyhttp/lru-send?style=for-the-badge&color=9F5E8C
[]: https://coveralls.io/github/tinyhttp/lru-send
[]: https://img.shields.io/npm/dt/lru-send?style=for-the-badge&color=9F5E8C
[]: https://img.shields.io/github/workflow/status/tinyhttp/lru-send/CI?style=for-the-badge&logo=github&label=&color=9F5E8C