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.
SequelizeSimpleCache
✓ import SequelizeSimpleCache from 'sequelize-simple-cache';
✗ const { SequelizeSimpleCache } = require('sequelize-simple-cache');
The package has a single default export. In CommonJS, use require('sequelize-simple-cache').default or just require() as shown in older docs.
init
✓ const cachedUser = cache.init(modelDefiner(sequelize));
✗ const cachedUser = cache.init('User');
init expects a Sequelize model instance (returned by model definer function), not a name string.
cache instance
✓ const cache = new SequelizeSimpleCache({ User: { ttl: 300 } });
✗ const cache = new SequelizeSimpleCache(['User']);
Constructor takes an object mapping model names to options (ttl in seconds), not an array.
model definition
✓ class User extends Model {}; module.exports = (sequelize) => User.init({ ... }, { sequelize });
✗ module.exports = (sequelize) => { const User = sequelize.define('User', { ... }); return User; };
The package expects models defined using the modern Model-based init() approach, not sequelize.define.
Shows setup of Sequelize connection, model definition using Model.init, cache initialization with options, and a basic findOne query that uses the cache.
const Sequelize = require('sequelize');
const SequelizeSimpleCache = require('sequelize-simple-cache');
const sequelize = new Sequelize(process.env.DB_NAME || 'test', process.env.DB_USER || 'root', process.env.DB_PASS || '', {
host: process.env.DB_HOST || 'localhost',
dialect: 'mysql'
});
class User extends Sequelize.Model {}
User.init({
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
name: { type: Sequelize.STRING },
email: { type: Sequelize.STRING }
}, { sequelize, modelName: 'User' });
const cache = new SequelizeSimpleCache({ User: { ttl: 60 } });
const CachedUser = cache.init(User);
async function main() {
await sequelize.sync({ force: true });
await CachedUser.create({ name: 'Alice', email: 'alice@example.com' });
const user = await CachedUser.findOne({ where: { name: 'Alice' } });
console.log('Cached user:', user.toJSON());
process.exit(0);
}
main().catch(err => { console.error(err); process.exit(1); });
Errors
Common errors & fixes
SequelizeSimpleCache is not a constructor
Using named import instead of default import in ES modules, or destructuring in CommonJS.
fixUse `import SequelizeSimpleCache from 'sequelize-simple-cache'` (ESM) or `const SequelizeSimpleCache = require('sequelize-simple-cache')` (CJS). Cannot read property 'init' of undefined
Model not properly exported/returned from model definer function.
fixEnsure model definer returns the model class (e.g., `return User.init(...)`).
Model "User" is not configured in the cache
Model name (from modelName option or class name) doesn't match any key in the cache constructor object.
fixCheck the model's modelName or use the class name; add that key to the cache options.
SequelizeSimpleCache requires sequelize >=4.x.x
Installed alongside an incompatible sequelize version.
fixInstall sequelize version 4 or later: `npm install sequelize@^4` or higher.
Audit
Dependencies
sequelizerequiredPeer dependency – required to wrap models with caching