Registry / database / mysql-cache-redis

mysql-cache-redis

JSON →
library0.0.8jsnpmunverified

A Node.js MySQL caching framework backed by Redis. Version 0.0.8 automatically caches SQL query results in Redis (database 0) with configurable TTL and lazy expiration. On data mutations, it invalidates cached tables. Requires mysql and redis packages as peer dependencies. Suitable for read-heavy workloads, but has limited documentation and appears in early development stages. Unlike more mature solutions (e.g., catbox), it provides an automatic but opaque caching strategy keyed by SQL strings.

npm install mysql-cache-redis
INSTALL
IMPORT
SIG · MYSQL-CACHE-REDIS
M
mysql-cache-redis
databasejavascriptv0.0.8
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
const mcr = require('mysql-cache-redis');
import mcr from 'mysql-cache-redis';
Package is CommonJS-only; ESM import will fail.
bind
const { bind } = require('mysql-cache-redis');
import { bind } from 'mysql-cache-redis';
Named export 'bind' is not available as ESM.
connect
const { connect } = require('mysql-cache-redis');
Use after bind(). Returns a connection object with query and release methods.

Configures MySQL pool and Redis client, binds to mysql-cache-redis, and executes a cached query.

const mcr = require('mysql-cache-redis'); const mysql = require('mysql'); const redis = require('redis'); const mysqlConfig = { host: 'localhost', port: 3306, database: 'test', username: 'root', password: process.env.MYSQL_PASSWORD ?? '', connectionLimit: 10 }; const redisConfig = { host: 'localhost', port: 6379 }; let pool = mysql.createPool(mysqlConfig); let client = redis.createClient(redisConfig); const mcroptions = { cacheTime: 60 * 60, delayTime: 60 * 30, isRelease: false }; mcr.bind(pool, client, mcroptions); global.mcr = mcr; // Usage (async () => { try { let connect = mcr.connect(); let data = await connect.query('SELECT * FROM users WHERE id=?', [1]); console.log(data); connect.release(); } catch (err) { console.error(err); } })();
Debug
Known issues
gotchaPackage uses eval() or similar to parse SQL? No, but caching key is raw SQL string — may cause collisions for parameterized queries with same SQL but different parameters.
fix
Always use parameterized queries; avoid dynamic SQL concatenation.
affects: *
gotchaNo TypeScript typings shipped.
fix
Install @types/mysql-cache-redis if available, or declare module manually.
affects: *
gotchaThe package relies on redis DB 0 by default and does not allow custom DB selection.
fix
Ensure Redis DB 0 is unused by other applications, or fork and modify source.
affects: *
gotchaNo automated invalidation on UPDATE/DELETE — requires manual cache flush or waits for TTL.
fix
Use TRIGGERs or application-level cache-busting upon write operations.
affects: *
gotchaPackage is not actively maintained; last update 2017.
fix
Consider alternatives like catbox or redis-mock-cache.
affects: *
Errors
Common errors & fixes
TypeError: mcr.bind is not a function
Using ESM import instead of CommonJS require().
fix
Change import statement to const mcr = require('mysql-cache-redis');
Error: bind must be called before connect
Calling mcr.connect() before mcr.bind(pool, client, options).
fix
Ensure bind() is called exactly once before any connect() calls.
Error: Redis connection refused
Redis server not running or wrong host/port.
fix
Start Redis server and verify redisConfig host/port values.
Upgrade
Version history
0.0.8latest on npm
Audit
Dependencies
mysqlrequiredPeer dependency for MySQL connection pooling
redisrequiredPeer dependency for Redis client
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
mysql-cache-redis — npm install mysql-cache-redis · libregistry