@platform-x/hep-cache-manager
v1.0.23
Published
Universal cache manager supporting multiple platforms with a unified interface
Downloads
2,853
Readme
HEP Cache Manager
High-performance Redis-based cache management system with MongoDB synchronization and Stale-While-Revalidate (SWR) patterns.
Features
- Redis-powered caching with sub-millisecond retrieval
- Real-time sync via MongoDB Change Streams
- SWR pattern for immediate responses
- Configurable TTL and refresh strategies
Quick Start
Prerequisites: Node.js, Redis, MongoDB
# Install
npm install
# Configure environment
REDIS_HOST=localhost
MONGODB_URI=mongodb://localhost:27017/hep-cache
# Run
npm startBasic Usage
const cacheManager = require('./cache-manager');
// Get/set with automatic expiration
const data = await cacheManager.get('user-profile', userId);
await cacheManager.set('user-profile', userId, userData);
// SWR - returns stale data immediately, refreshes in background
const freshData = await cacheManager.getSWR('feed-data', feedId);Configuration
// Cache strategies per data type
{
'user-profile': {
ttl: 3600, // 1 hour
swr: true, // Enable SWR
proactiveRefresh: 900 // Refresh after 15min
}
}Cache Key Format: v1:feedType:entityId
Development
npm test # Run tests
npm run lint # Code linting
npm run build # Build for productionProject Structure:
src/services/- Core cache and sync servicessrc/config/- Cache strategies and Redis setupsrc/utils/- Key generation and serialization
Health Check
curl http://localhost:3000/healthLicense
MIT
