{"id":46340,"library":"sequelize-simple-cache","title":"Sequelize Simple Cache","description":"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.","status":"active","version":"1.3.5","language":"javascript","source_language":"en","source_url":"git://github.com/funny-bytes/sequelize-simple-cache","tags":["javascript","Sequelize","transparent","cache","client-side","in-memory","typescript"],"install":[{"cmd":"npm install sequelize-simple-cache","lang":"bash","label":"npm"},{"cmd":"yarn add sequelize-simple-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add sequelize-simple-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – required to wrap models with caching","package":"sequelize","optional":false}],"imports":[{"note":"The package has a single default export. In CommonJS, use require('sequelize-simple-cache').default or just require() as shown in older docs.","wrong":"const { SequelizeSimpleCache } = require('sequelize-simple-cache');","symbol":"SequelizeSimpleCache","correct":"import SequelizeSimpleCache from 'sequelize-simple-cache';"},{"note":"init expects a Sequelize model instance (returned by model definer function), not a name string.","wrong":"const cachedUser = cache.init('User');","symbol":"init","correct":"const cachedUser = cache.init(modelDefiner(sequelize));"},{"note":"Constructor takes an object mapping model names to options (ttl in seconds), not an array.","wrong":"const cache = new SequelizeSimpleCache(['User']);","symbol":"cache instance","correct":"const cache = new SequelizeSimpleCache({ User: { ttl: 300 } });"},{"note":"The package expects models defined using the modern Model-based init() approach, not sequelize.define.","wrong":"module.exports = (sequelize) => { const User = sequelize.define('User', { ... }); return User; };","symbol":"model definition","correct":"class User extends Model {}; module.exports = (sequelize) => User.init({ ... }, { sequelize });"}],"quickstart":{"code":"const Sequelize = require('sequelize');\nconst SequelizeSimpleCache = require('sequelize-simple-cache');\n\nconst sequelize = new Sequelize(process.env.DB_NAME || 'test', process.env.DB_USER || 'root', process.env.DB_PASS || '', {\n  host: process.env.DB_HOST || 'localhost',\n  dialect: 'mysql'\n});\n\nclass User extends Sequelize.Model {}\nUser.init({\n  id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },\n  name: { type: Sequelize.STRING },\n  email: { type: Sequelize.STRING }\n}, { sequelize, modelName: 'User' });\n\nconst cache = new SequelizeSimpleCache({ User: { ttl: 60 } });\nconst CachedUser = cache.init(User);\n\nasync function main() {\n  await sequelize.sync({ force: true });\n  await CachedUser.create({ name: 'Alice', email: 'alice@example.com' });\n  const user = await CachedUser.findOne({ where: { name: 'Alice' } });\n  console.log('Cached user:', user.toJSON());\n  process.exit(0);\n}\n\nmain().catch(err => { console.error(err); process.exit(1); });","lang":"javascript","description":"Shows setup of Sequelize connection, model definition using Model.init, cache initialization with options, and a basic findOne query that uses the cache."},"warnings":[{"fix":"Use short TTLs or manually clear cache by calling cache.flush() on write operations.","message":"Cache is only invalidated by TTL, not by writes. Creating or updating cached models will return stale data until TTL expires.","severity":"gotcha","affected_versions":"*"},{"fix":"Always verify the modelName used in User.init() or sequelize.define (deprecated).","message":"Model name must match exactly the key passed to the cache constructor. If modelName option differs from class name, use that name.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade Sequelize to v5 or v6.","message":"Sequelize v4 support is deprecated. The package is tested with v5 and v6. v4 may work but is not guaranteed.","severity":"deprecated","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Pass an object like { ModelName: { ttl: seconds } } instead of an array.","message":"Version 1.0.0 changed the API from array of model names to an object with options.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use Node 12 or later.","message":"Requires Node >=12. Using older versions will cause errors.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'1.3.5':18 '12':54 '4':45 '5':50 '6':52 'api':69 'base':27 'better':93 'cach':3,12,19,97 'chang':70 'client':7,99 'client-sid':6,98 'configur':39 'data':40 'databas':60 'differenti':61 'e.g':38 'frequent':32 'high':80,84 'high-volum':83 'high-writ':79 'ideal':28 'in-memori':9,101 'infrequ':30 'invalid':20 'javascript':94 'layer':13 'lightweight':65 'live':25 'memcach':90 'memori':11,103 'model':75 'node':53 'orm':16 'read':33 'redi':88 'requir':71 'row':37 'scenario':86 'sequel':1,15,43,58,95 'sequelize-support':57 'side':8,100 'simpl':2 'simpli':72 'suitabl':77 'support':59 'tabl':34 'test':48 'time':23 'time-to-l':22 'transpar':5,67,96 'ttl':26 'typescript':104 'updat':31 'version':17,44 'volum':85 'work':41 'would':91 'wrap':73 'write':81","created_at":"2026-06-07T12:59:26.426043+00:00","updated_at":"2026-06-07T12:59:26.426043+00:00","problems":[{"fix":"Use `import SequelizeSimpleCache from 'sequelize-simple-cache'` (ESM) or `const SequelizeSimpleCache = require('sequelize-simple-cache')` (CJS).","cause":"Using named import instead of default import in ES modules, or destructuring in CommonJS.","error":"SequelizeSimpleCache is not a constructor"},{"fix":"Ensure model definer returns the model class (e.g., `return User.init(...)`).","cause":"Model not properly exported/returned from model definer function.","error":"Cannot read property 'init' of undefined"},{"fix":"Check the model's modelName or use the class name; add that key to the cache options.","cause":"Model name (from modelName option or class name) doesn't match any key in the cache constructor object.","error":"Model \"User\" is not configured in the cache"},{"fix":"Install sequelize version 4 or later: `npm install sequelize@^4` or higher.","cause":"Installed alongside an incompatible sequelize version.","error":"SequelizeSimpleCache requires sequelize >=4.x.x"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/funny-bytes/sequelize-simple-cache#readme","github":"git://github.com/funny-bytes/sequelize-simple-cache","docs":null,"changelog":null,"pypi":null,"npm":"sequelize-simple-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}