4.0.7 • Published 7 months ago

descript-redis-cache v4.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

descript-redis-cache

Plugin to use Redis as a cache in Descript

Usage

import de from 'descript';
import { Cache } from 'descript-redis-cache';

const redisCache = new Cache(options);

// subscribe to events if necessary
// @see https://github.com/luin/ioredis#connection-events
redisCache.getClient()
    .on('reconnecting', () => {/* ... */})
    .on('error', () => {/* ... */})
    .on('close', () => {/* ... */})
    .on('end', () => {/* ... */});

const myBlock = de.http({
    block: { /* ... */ },
    options: {
        key: ({ params }) => '_some_cache_key_by_params_',
        cache: redisCache,
    }
});

Options

import type { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';

export interface Options {
    // key TTL in seconds (default: 60 * 60 * 24)
    defaultKeyTTL?: number;
    // increment generation to invalidate all key across breaking changes releases (default: 1)
    generation?: number;
    // read timeout in milliseconds (default: 100)
    readTimeout?: number;
    redis: RedisOptions | { startupNodes: ClusterNode[], options?: ClusterOptions };
}

Logger

Optionally you can pass logger object in the constructor. It should implement standard Console methods.

const redisCache = new deRedisCache(options, logger);
4.0.7

7 months ago

4.0.5

7 months ago

4.0.4

7 months ago

4.0.6

7 months ago

4.0.3

8 months ago

4.0.2

8 months ago

3.1.1

8 months ago

4.0.1

8 months ago

3.0.0

3 years ago