Registry / database / egg-cache

egg-cache

JSON →
library0.0.7jsnpmunverified

Egg.js cache plugin based on cache-manager. Version 0.0.7 (released 2019) supports memory and external stores like Redis via cache-manager stores. Provides set/get/del/has/reset via app.cache, with optional TTL and closure/promise support. Low release cadence; no recent updates. Differentiator: integrates seamlessly into Egg.js lifecycle and configuration.

npm install egg-cache
INSTALL
IMPORT
SIG · EGG-CACHE
E
egg-cache
databasejavascriptv0.0.7
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.

plugin
✓ // config/plugin.js module.exports = { cache: { enable: true, package: 'egg-cache', }, };
✗ // Incorrect: not a regular import but a plugin declaration in Egg
Egg plugin registration, not a direct import. The plugin exposes app.cache.
app.cache
✓ await app.cache.set('key', 'value');
✗ const { cache } = require('egg-cache');
app.cache is available after plugin enable, not imported directly.
store
✓ const store = app.cache.store('redis'); await store.set('foo', 'bar');
✗ app.cache.redis.set('foo', 'bar');
Use app.cache.store(name) to get a specific store instance.

Demonstrates Egg.js plugin configuration and basic cache set/get operations.

// Enable plugin in config/plugin.js module.exports = { cache: { enable: true, package: 'egg-cache', }, }; // Configure in config/config.default.js module.exports = { cache: { default: 'memory', stores: { memory: { driver: 'memory', max: 100, ttl: 0, }, }, }, }; // Use in your controller const { ctx } = this; await ctx.app.cache.set('foo', 'bar', 60); const value = await ctx.app.cache.get('foo'); console.log(value); // 'bar'
Debug
Known issues
breakingVersion 0.0.7 may have breaking changes from earlier versions; check CHANGELOG (missing)
fix
Stick to known working version or migrate to newer alternatives like egg-redis.
affects: 0.0.7
gotchastore name in config uses 'driver' key but actual store engine must provide a create() function
fix
Refer to cache-manager store docs for correct driver format.
affects: >=0.0.1
deprecatedPackage received no updates since 2019; cache-manager v3+ may introduce incompatible changes
fix
Consider using @eggjs/cache or other actively maintained cache plugins.
affects: >=0.0.7
gotchattl: 0 in config means no expiration? Check cache-manager docs: 0 may mean never expire but some stores treat differently
fix
Set ttl to a positive number or undefined to avoid ambiguity.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'egg-cache'
egg-cache not installed or plugin not enabled in config/plugin.js
fix
Run: npm install egg-cache --save and add to config/plugin.js as described.
app.cache is undefined
Plugin not loaded or disabled in config/plugin.js
fix
Check config/plugin.js has exports.cache = { enable: true, package: 'egg-cache' }
Upgrade
Version history
0.0.7latest on npm
Audit
Dependencies
cache-managerrequiredCore caching abstraction layer
Agent activity
14 hits · last 30 days
node
12
Resources
egg-cache — npm install egg-cache · libregistry