🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@inferagraph/redis-cache-provider

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inferagraph/redis-cache-provider

Redis-backed cache provider for @inferagraph/core.

latest
Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
6
-70%
Maintainers
1
Weekly downloads
 
Created
Source

@inferagraph/redis-cache-provider

Redis-backed CacheProvider for @inferagraph/core's AIEngine. Suitable for production deployments where the built-in in-memory lruCache is insufficient — e.g. when you want a cache shared across server processes, persisted across browser reloads, or sized larger than available process memory.

Honors the same maxEntries + ttl semantics as lruCache, so swapping providers is a one-line change.

Installation

pnpm add @inferagraph/redis-cache-provider @inferagraph/core redis

Usage

import { AIEngine } from '@inferagraph/core';
import { redisCache } from '@inferagraph/redis-cache-provider';

const cache = redisCache({
  url: process.env.REDIS_URL ?? 'redis://localhost:6379',
  // Optional bounds. If both are unset, defaults to (500, '24h') — same as lruCache.
  maxEntries: 1000,
  ttl: '12h',
});

const engine = new AIEngine({ /* ... */ });
engine.setCache(cache);

Configuration

OptionRequiredDescription
urlOne of url / clientRedis connection URL (e.g. redis://localhost:6379, rediss://...).
clientOne of url / clientPre-built node-redis client. When provided, url is ignored. Useful for tests and connection-pool reuse.
prefixNoKey prefix to namespace this cache (default infera:cache:). Lets multiple InferaGraph instances share a Redis instance without collisions.
maxEntriesNoMaximum entries to retain. -1 disables the bound. See defaults note below.
ttlNoTime-to-live per entry. Number (ms) or duration string (5m, 2h, 7d, 1w). -1 / '-1' disables the bound.

Defaults: when both maxEntries and ttl are unset, the provider defaults to (500, '24h'). When only one is set, the unset bound is treated as no-limit. This matches lruCache's contract.

Notes

  • The provider connects lazily on first operation, so constructing it is cheap and won't throw.
  • maxEntries is enforced by maintaining a Redis ZSET index at ${prefix}__index keyed by insertion timestamp; on overflow, the oldest key is evicted (insertion-order; not strict LRU).
  • clear() uses SCAN (never KEYS) so it is safe on large datasets.

License

MIT

Keywords

inferagraph

FAQs

Package last updated on 06 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts