Registry / database / mikro-orm-cache-adapter-redis

mikro-orm-cache-adapter-redis

JSON →
library4.0.1jsnpmunverified

A Redis cache adapter for Mikro-ORM, providing high-performance caching using Node.js v8 serialize/deserialize instead of JSON. Version 4.0.1 requires ioredis ^5.3.2 and Mikro-ORM 4.x (not specified but likely). Uses structured clone algorithm for better handling of Buffers, Dates, Maps, Sets, and cyclic objects, but cannot serialize functions, symbols, or uncopyable data. Supports passing a pre-configured ioredis client or connection options. Available on npm, ships TypeScript types.

npm install mikro-orm-cache-adapter-redis
INSTALL
IMPORT
SIG · MIKRO-ORM-CACHE-AD
M
mikro-orm-cache-adapter-redis
databasejavascriptv4.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisCacheAdapter
import { RedisCacheAdapter } from 'mikro-orm-cache-adapter-redis'
import RedisCacheAdapter from 'mikro-orm-cache-adapter-redis'
Named export, not default.
RedisCacheAdapter
const { RedisCacheAdapter } = require('mikro-orm-cache-adapter-redis')
const RedisCacheAdapter = require('mikro-orm-cache-adapter-redis')
CommonJS destructuring required.
RedisCacheAdapter (in MikroORM config)
resultCache: { adapter: RedisCacheAdapter, options: { ... } }
resultCache: { adapter: 'RedisCacheAdapter', options: { ... } }
Pass the class, not a string.

Configures Mikro-ORM with Redis cache adapter using ioredis connection options.

import { MikroORM } from '@mikro-orm/core'; import { RedisCacheAdapter } from 'mikro-orm-cache-adapter-redis'; const orm = await MikroORM.init({ entities: ['./dist/entities'], dbName: 'test', type: 'sqlite', resultCache: { adapter: RedisCacheAdapter, options: { host: process.env.REDIS_HOST ?? 'localhost', port: parseInt(process.env.REDIS_PORT ?? '6379'), password: process.env.REDIS_PASSWORD ?? '', keyPrefix: 'mikro', debug: false, }, }, }); // Use ORM with caching await orm.em.findOne(User, { id: 1 }, { cache: 60 }); // cache for 60 seconds await orm.close();
Debug
Known issues
gotchaCannot serialize functions, symbols, or uncopyable data with v8 serialize; these will throw an error.
fix
Use Mikro-ORM custom serializers or custom types for such data before caching.
affects: >=4.0.0
deprecatedThe 'keyPrefix' default 'mikro' is not configurable via environment variables.
fix
Set keyPrefix in options to customize.
affects: >=4.0.0
gotchaPassing a client instance (options.client) overrides all other connection options.
fix
Provide either a client or connection options, not both.
affects: >=4.0.0
gotchaDebug mode logs JSON.stringify of cache data; actual cache uses v8 serialize which differs in output.
fix
Use debug only for development; production should disable it.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: RedisCacheAdapter is not a constructor
Default import instead of named import in ESM.
fix
import { RedisCacheAdapter } from 'mikro-orm-cache-adapter-redis'
Error: Cannot find module 'ioredis'
Missing peer dependency ioredis.
fix
npm install ioredis
Error: Cannot find module 'mikro-orm-cache-adapter-redis'
Package not installed or typo in package name.
fix
npm install mikro-orm-cache-adapter-redis ioredis
Error: Invalid cache adapter. Expected an object with a 'name' property.
Passed string instead of class for adapter in MikroORM config.
fix
resultCache: { adapter: RedisCacheAdapter, options: {...} }
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
ioredisrequiredPeer dependency; required to connect to Redis.
Agent activity
3 hits · last 30 days
node
2
Resources
mikro-orm-cache-adapter-redis — npm install mikro-orm-cache-adapter-redis · libregistry