4.0.7 • Published 10 months ago

descript-redis-cache v4.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
10 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

10 months ago

4.0.5

10 months ago

4.0.4

10 months ago

4.0.6

10 months ago

4.0.3

10 months ago

4.0.2

10 months ago

3.1.1

10 months ago

4.0.1

10 months ago

3.0.0

4 years ago