Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tinyhttp/lru-send

⏩ LRU-based caching middleware for Node.js
https://github.com/tinyhttp/lru-send

caching http lru memo memoization nodejs performance tinyhttp

Last synced: about 1 month ago
JSON representation

⏩ LRU-based caching middleware for Node.js

Awesome Lists containing this project

README

        

# lru-send

[![npm][npm-img]][npm-url] [![GitHub Workflow Status][actions-badge]][github-actions] [![Coverage][cov-img]][cov-url]

LRU-based caching middleware for Node.js that patches `res.send`.

## Features

- 😲 [**~336x faster**](bench) for heavy operations
- ⚡ ESM-only
- ✨ types out of the box
- 🟥 (optionally) supports [Redis](http://redis.io/)

## Install

```sh
pnpm i lru-send
```

## Examples

### In-memory

```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)
```

### Redis

```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)
```

[npm-url]: https://npmjs.com/package/lru-send
[github-actions]: https://github.com/tinyhttp/lru-send/actions
[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/lru-send?style=for-the-badge&color=9F5E8C
[cov-url]: https://coveralls.io/github/tinyhttp/lru-send
[npm-img]: https://img.shields.io/npm/dt/lru-send?style=for-the-badge&color=9F5E8C
[actions-badge]: https://img.shields.io/github/actions/workflow/status/tinyhttp/lru-send/ci.yml?branch=master&style=for-the-badge&logo=github&label=&color=9F5E8C