Registry / database / sequelize-simple-cache

sequelize-simple-cache

JSON →
library1.3.5jsnpmunverified

A transparent, client-side, in-memory caching layer for Sequelize ORM, version 1.3.5. Cache invalidation is time-to-live (TTL) based. Ideal for infrequently updated, frequently read tables with few rows (e.g., configuration data). Works with Sequelize versions 4 and up (tested with 5 and 6), Node >=12, and all Sequelize-supported databases. Differentiates itself by being lightweight and transparent—no API changes required; simply wrap your models. Not suitable for high-write or high-volume scenarios where Redis or Memcached would be better.

npm install sequelize-simple-cache
INSTALL
IMPORT
SIG · SEQUELIZE-SIMPLE-C
S
sequelize-simple-cache
databasejavascriptv1.3.5
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.

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); });
Debug
Known issues
gotchaCache is only invalidated by TTL, not by writes. Creating or updating cached models will return stale data until TTL expires.
fix
Use short TTLs or manually clear cache by calling cache.flush() on write operations.
affects: *
gotchaModel name must match exactly the key passed to the cache constructor. If modelName option differs from class name, use that name.
fix
Always verify the modelName used in User.init() or sequelize.define (deprecated).
affects: *
deprecatedSequelize v4 support is deprecated. The package is tested with v5 and v6. v4 may work but is not guaranteed.
fix
Upgrade Sequelize to v5 or v6.
affects: >=1.0.0 <2.0.0
breakingVersion 1.0.0 changed the API from array of model names to an object with options.
fix
Pass an object like { ModelName: { ttl: seconds } } instead of an array.
affects: >=1.0.0
gotchaRequires Node >=12. Using older versions will cause errors.
fix
Use Node 12 or later.
affects: *
Errors
Common errors & fixes
SequelizeSimpleCache is not a constructor
Using named import instead of default import in ES modules, or destructuring in CommonJS.
fix
Use `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.
fix
Ensure 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.
fix
Check 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.
fix
Install sequelize version 4 or later: `npm install sequelize@^4` or higher.
Upgrade
Version history
1.3.5latest on npm
Audit
Dependencies
sequelizerequiredPeer dependency – required to wrap models with caching
Agent activity
11 hits · last 30 days
node
8
Meta
2
Resources
sequelize-simple-cache — npm install sequelize-simple-cache · libregistry