Configuration

Configure redis-graph-cache to match your application's needs.

const cache = new RedisGraphCache(schema, {
  redis: { /* ... */ },
  cache: { /* ... */ },
  limits: { /* ... */ },
  resilience: { /* ... */ },
  monitoring: { /* ... */ },
  safety: { /* ... */ },
});

All sections are optional; partial configs are deep-merged with the defaults shown below.

Redis Configuration

Extends standard ioredis RedisOptions. Configure connection settings and pooling.

OptionTypeDefaultDescription
hoststring'localhost'Redis host
portnumber6379Redis port
dbnumber0Redis database number
passwordstringRedis auth password
keyPrefixstring''Prepended to every key. Auto-suffixes : if missing
poolSizenumber1Number of ioredis clients (round-robined). Use 4–8 in production
...all other ioredis optionsTLS, sentinel, retry strategies, etc.

Key namespacing

When keyPrefix is set, clearAllCache switches from FLUSHDB to non-blocking scoped SCAN + UNLINK. Strongly recommended when sharing Redis with other apps/envs.

Cache Configuration

Configure caching behavior, TTL defaults, and serialization options.

OptionTypeDefaultDescription
defaultTTLnumber (s)3600Fallback TTL when schema doesn't specify one
enableCompressionbooleanfalseAuto-zlib entity payloads larger than threshold
compressionThresholdnumber (bytes)1024Min payload size to compress
enableL1CachebooleanfalseReserved (in-process L1 cache, not yet implemented)
serializerSerializerTAGGED_SERIALIZERLossless tagged JSON. Pass JSON_SERIALIZER for raw JSON
l1CacheSizenumber1000Reserved

Limits Configuration

Configure operational limits to prevent resource exhaustion.

OptionTypeDefaultDescription
maxHydrationDepthnumber5Throws HydrationDepthExceededError if exceeded
maxEntitiesPerRequestnumber1000Cap on entities hydrated per call
maxMemoryUsagePerOperationnumber (bytes)100 MBThrows MemoryLimitError if exceeded
maxConcurrentOperationsnumber100Reserved
batchSizenumber100Pipeline batch size for bulk ops

Resilience Configuration

Configure circuit breaker, retry logic, and fallback strategies.

resilience: {
  circuitBreaker: { threshold: 5, timeout: 60000, resetTimeout: 30000 },
  retry: { maxAttempts: 3, baseDelay: 100, maxDelay: 2000, backoffFactor: 2 },
  fallback: { enabled: true, strategy: 'null' }, // 'null' | 'empty' | 'cached' | 'custom'
}
SectionOptionDefaultDescription
circuitBreakerthreshold5Consecutive failures before tripping OPEN
timeout60000 msMax op duration before counted as failure
resetTimeout30000 msOPEN → HALF_OPEN cool-down
retrymaxAttempts3Max retries per op
baseDelay100 msInitial backoff
maxDelay2000 msCap on exponential backoff
backoffFactor2Multiplier per attempt
fallbackenabledtrueWhether to apply a fallback when ops fail
strategy'null''null' | 'empty' | 'cached' | 'custom'

Monitoring Configuration

Configure metrics collection and logging.

OptionTypeDefaultDescription
enableMetricsbooleantrueTrack hits, misses, latency
enableDebugModebooleanfalseReserved
enableAuditLogbooleanfalseReserved
metricsIntervalnumber60000Reserved
logLevel'error' | 'warn' | 'info' | 'debug''info'Reserved

Safety Configuration

Configure production safety guards.

OptionTypeDefaultDescription
productionModebooleanNODE_ENV === 'production'Blocks clearAllCache unless allowProduction: true

Reserved options

cache.enableL1Cache, cache.l1CacheSize, and redis.connectionPool are accepted for forward compatibility but are not currently used. Use redis.poolSize for connection pooling.