Registry / database / sequelize-transparent-cache

sequelize-transparent-cache

JSON →
library2.3.0jsnpmunverified

Abstract, transparent caching layer for Sequelize ORM (v2.3.0). Works with any cache backend via adaptors (ioredis, memcached, etc.). Cached objects are full Sequelize instances preserving model methods. Lightweight with zero additional dependencies. Compatible with Sequelize >=5. Supports automatic cache for findByPk, create, update, destroy, and reload, plus arbitrary query caching with explicit keys.

npm install sequelize-transparent-cache
INSTALL
IMPORT
SIG · SEQUELIZE-TRANSPAR
S
sequelize-transparent-cache
databasejavascriptv2.3.0
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.

default export (sequelizeCache factory)
import sequelizeCache from 'sequelize-transparent-cache'
const sequelizeCache = require('sequelize-transparent-cache')
Package is ESM-only? The docs show require() but package may support both. Use import in ES modules.
sequelizeCache
const sequelizeCache = require('sequelize-transparent-cache')
CommonJS require is shown in README examples.
withCache
const { withCache } = sequelizeCache(adaptor)
const { withCache } = require('sequelize-transparent-cache')
withCache is returned from the factory function, not from the package directly.

Shows setup with ioredis adaptor, model wrapping, and cached queries (findAll, findByPk, update).

const Redis = require('ioredis'); const redis = new Redis(); const RedisAdaptor = require('sequelize-transparent-cache-ioredis'); const redisAdaptor = new RedisAdaptor({ client: redis, namespace: 'model', lifetime: 3600 }); const sequelizeCache = require('sequelize-transparent-cache'); const { withCache } = sequelizeCache(redisAdaptor); const Sequelize = require('sequelize'); const sequelize = new Sequelize('database', 'user', 'password', { dialect: 'mysql', host: 'localhost' }); const User = withCache(sequelize.import('./models/user')); await sequelize.sync(); await User.cache('active-users').findAll({ where: { status: 'ACTIVE' } }); const user = await User.cache().findByPk(1); await user.cache().update({ name: 'Vikki' });
Debug
Known issues
gotchaCache adaptor required - without an adaptor the cache() call will throw or behave unexpectedly.
fix
Install and configure an adaptor like sequelize-transparent-cache-ioredis.
affects: all
gotchaSequelize v5+ required - peer dependency is 'sequelize': '>=5', using older Sequelize may break.
fix
Upgrade Sequelize to version >=5.
affects: all
breakingcache() wraps a limited subset of methods (findByPk, create, etc.) - not all Sequelize methods are cached.
fix
Verify the method you need is listed in the README or manually cache using explicit key.
affects: all
gotchawithCache must be called per model - passing already wrapped models through again may cause double wrapping.
fix
Call withCache only on the original sequelize.import result.
affects: all
Errors
Common errors & fixes
sequelizeCache is not a function
Importing default export incorrectly; using require on a named export that doesn't exist.
fix
Use `const sequelizeCache = require('sequelize-transparent-cache')` or import default.
withCache is not a function
Attempting to destructure withCache from the package import rather than from the factory result.
fix
Correct: `const { withCache } = sequelizeCache(adaptor)`.
Cannot find module 'sequelize-transparent-cache-ioredis'
Missing adaptor package; only core package installed.
fix
Run `npm install sequelize-transparent-cache-ioredis` (or your chosen adaptor).
Upgrade
Version history
2.3.0latest on npm
Audit
Dependencies
sequelizerequiredPeer dependency - required for model methods and instance wrappers
Agent activity
11 hits · last 30 days
node
8
Meta
2
Resources
sequelize-transparent-cache — npm install sequelize-transparent-cache · libregistry