Registry / storage / egg-lru

egg-lru

JSON →
library1.0.1jsnpmunverified

Egg.js plugin wrapping lru-cache to provide LRU caching in Egg applications. Version 1.0.1 (latest) supports both single and multi-client configurations. It integrates seamlessly with Egg's plugin system and offers simple key-value cache with optional time-to-live. Alternative to egg-redis for in-memory caching with LRU eviction policy.

npm install egg-lru
INSTALL
IMPORT
SIG · EGG-LRU
E
egg-lru
storagejavascriptv1.0.1
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.

app.lru
// Access via app.lru in Egg app
const lru = require('egg-lru');
egg-lru is a plugin; it does not export a module. Access is via app.lru after enabling the plugin.
Single client
app.lru.set('key', 'value'); app.lru.get('key');
Usage when configured with a single client.
Multiple clients
const long = app.lru.get('long'); long.set('key', 'value');
app.lru.long.set('key', 'value');
For multiple clients, use app.lru.get('clientName') to get the specific lru-cache instance.

How to enable, configure, and use egg-lru plugin in an Egg.js application.

// Enable plugin in config/plugin.js exports.lru = { enable: true, package: 'egg-lru', }; // Configure in config/config.default.js exports.lru = { client: { max: 1000, maxAge: 1000 * 60 * 60, }, app: true, agent: false, }; // Usage in controller 'use strict'; const Controller = require('egg').Controller; class HomeController extends Controller { async index() { const { ctx, app } = this; app.lru.set('foo', 'bar'); const value = app.lru.get('foo'); ctx.body = value; // 'bar' } } module.exports = HomeController;
Debug
Known issues
gotchaAccessing app.lru before plugin is loaded results in undefined
fix
Ensure plugin is enabled and accessed only after application start.
affects: >=1.0.0
gotchaUsing app.lru.get('clientName') returns undefined if client name does not exist
fix
Check if client exists before calling methods.
affects: >=1.0.0
breakingChanges in lru-cache major versions may affect behavior (e.g., options changed)
fix
Check lru-cache changelog and update configuration accordingly.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read property 'set' of undefined
app.lru is undefined because plugin not enabled or misconfigured.
fix
Ensure plugin is enabled in config/plugin.js and correctly configured.
lru.get is not a function
Using app.lru.get('client') returns a lru-cache instance, but mixing up single/multi client usage.
fix
For single client, use app.lru directly. For multi, use app.lru.get('clientName') first.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
lru-cacherequiredruntime dependency for LRU cache implementation
Agent activity
33 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources
egg-lru — npm install egg-lru · libregistry