# @types/koa-redis-cache

> TypeScript definitions for koa-redis-cache

Latest version **3.0.5** (published 2025-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/koa-redis-cache
pnpm add @types/koa-redis-cache
yarn add @types/koa-redis-cache
bun add @types/koa-redis-cache
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.5 |
| Published | 2025-10-24 |
| First published | 2018-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51445 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/koa-redis-cache
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-redis-cache
- npm.io page: https://npm.io/package/@types/koa-redis-cache

## Dependencies (2)

- [@types/koa](https://npm.io/package/@types/koa.md) *
- [@types/redis](https://npm.io/package/@types/redis.md) ^2.8.0

## Recent versions

- 3.0.5 (latest) — 2025-10-24
- 3.0.4 (ts5.1) — 2023-11-07
- 3.0.2 (ts4.3) — 2021-12-09
- 3.0.1 (ts3.6) — 2021-07-08
- 3.0.0 (ts3.4) — 2018-08-18
- 3.0.3 — 2023-10-18

## README

# Installation
> `npm install --save @types/koa-redis-cache`

# Summary
This package contains type definitions for koa-redis-cache (https://github.com/coderhaoxin/koa-redis-cache).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-redis-cache.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-redis-cache/index.d.ts)
````ts
import Koa = require("koa");
import * as Redis from "redis";

type onErrorCallback = (error: Error) => void;

type getPrefixCallback = (ctx: Koa.Context) => string;

declare namespace cache {
    interface CacheOptions {
        /**
         * redis key prefix, default is koa-redis-cache:
         * If a function is supplied, its signature should be function(ctx) {} and it should return a string to use as the redis key prefix
         */
        prefix?: string | getPrefixCallback | undefined;

        /**
         * redis expire time (second), default is 30 * 60 (30 min)
         */
        expire?: number | undefined;

        /**
         * if the passParam exists in the query string, skip the cache
         */
        passParam?: string | undefined;

        /**
         * max length of body size (in bytes) to cache.
         * if the size of the body exceeds maxLength, the body will not be cached.
         * default is: Infinity
         */
        maxLength?: number | undefined;

        /**
         * the routes to cache, default is ['(.*)'].
         * can be set to an array of routes (string), or an array of RouteOptions
         */
        routes?: RouteOptions[] | string[] | undefined;

        /**
         * the routes to exclude, default is [].
         * example: ['/api/(.*)', '/view/:id']
         */
        exclude?: string[] | undefined;

        /**
         * callback function for error, default is function() {}
         */
        onerror?: onErrorCallback | undefined;

        /**
         * redis options
         */
        redis?: RedisOptions | undefined;
    }

    interface RouteOptions {
        /**
         * the route to cache, example: '/api/(.*)'
         */
        route: string;

        /**
         * expiration time in seconds for cached responses for the route
         */
        expire?: number | undefined;
    }

    interface RedisOptions {
        /**
         * host name of the redis server, default: 'localhost'
         */
        host?: string | undefined;

        /**
         * port number of the redis server, default: 6379
         */
        port?: number | undefined;

        /**
         * node_redis options
         */
        options?: Redis.ClientOpts | undefined;
    }
}

declare function cache(opts?: cache.CacheOptions): Koa.Middleware;

export = cache;

````

### Additional Details
 * Last updated: Fri, 24 Oct 2025 04:02:41 GMT
 * Dependencies: [@types/koa](https://npmjs.com/package/@types/koa), [@types/redis](https://npmjs.com/package/@types/redis)

# Credits
These definitions were written by [Dima Mukhin](https://github.com/dimamukhin).

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