# @tcollinsworth/lrucache

> lru cache with express middleware for inspection/management

Latest version **1.0.4** (published 2025-04-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tcollinsworth/lrucache
pnpm add @tcollinsworth/lrucache
yarn add @tcollinsworth/lrucache
bun add @tcollinsworth/lrucache
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2025-04-22 |
| First published | 2023-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=18.12 |
| Dependencies | 5 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | troy.collinsworth@gmail.com |
| Maintainers | tcollinsworth |
| Keywords | lru, cache, express |

## Links

- npm: https://www.npmjs.com/package/@tcollinsworth/lrucache
- Repository: https://github.com/tcollinsworth/lrucache
- Homepage: https://github.com/tcollinsworth/lrucache#readme
- Issues: https://github.com/tcollinsworth/lrucache/issues
- npm.io page: https://npm.io/package/@tcollinsworth/lrucache

## Dependencies (5)

- [delay](https://npm.io/package/delay.md) ^6.0.0
- [express](https://npm.io/package/express.md) ^4.18.2
- [cronosjs](https://npm.io/package/cronosjs.md) ^1.7.1
- [lru-cache](https://npm.io/package/lru-cache.md) ^10.0.0
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2025-04-22
- 1.0.3 — 2023-07-05
- 1.0.2 — 2023-07-05
- 1.0.1 — 2023-07-05
- 1.0.0 — 2023-07-05

## README

# LruCache

This lib uses [lru-cache](https://www.npmjs.com/package/lru-cache).

It provides:

  * Tracks hits and misses on get
  * Express middleware for inspection and management of all caches
    * Statistics - hits, misses, entry count
  * Scheduled periodic pruning and clearing

# Usage

```javascript
const app = express()

const options = {
  periodicClearing: { autoStart: true },
  periodicPruning: { autoStart: true },
  nativeCacheOptions: { max: 10000, ttl: 86400000 },
}

const aCache = new LruCache(options)
const bCache = new LruCache(options)

const lruExpress = new LruCacheExpressMiddleware()

app.use('/lru-cache', lruExpress.getMiddleware())
```

# REST APIs

 * /purgeStale?cacheName=ALL | cacheName
 * /clearCache?cacheName=ALL | cacheName
 * /getOptions?cacheName=ALL | cacheName
 * /getStats?cacheName=ALL | cacheName
 * /resetStats?cacheName=ALL | cacheName

# Periodic Scheduling

Uses [cronosjs](https://www.npmjs.com/package/cronosjs)

```text
second, minute, hour, day of month, month, day of week, year
scheduled to run every Saturday @ 8:00:10pm  === '10 0 20 * * 6 *'
/*
  *  *  *  *  *  *  *    Field              Allowed values    Special symbols
  |  |  |  |  |  |  |    -----------------  ---------------   ---------------
  `--|--|--|--|--|--|->  Second (optional)  0-59              * / , -
     `--|--|--|--|--|->  Minute             0-59              * / , -
        `--|--|--|--|->  Hour               0-23              * / , -
           `--|--|--|->  Day of Month       1-31              * / , - ? L W
              `--|--|->  Month              1-12 or JAN-DEC   * / , -
                 `--|->  Day of Week        0-7 or SUN-SAT    * / , - ? L #
                    `->  Year (optional)    0-275759          * / , -
```

---
_Source: https://npm.io/package/@tcollinsworth/lrucache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
