feat: implement always-adaptive caching with getCacheStats monitoring

Replaces lazy mode concept with always-adaptive caching strategy:

- Rename getLazyModeStats() → getCacheStats() with enhanced metrics
- Change lazyModeEnabled boolean → cachingStrategy enum ('preloaded' | 'on-demand')
- Update preloading threshold from 30% to 80% for better cache utilization
- Add comprehensive production monitoring and diagnostics
- Add memory detection for containers (Docker/K8s cgroups v1/v2)
- Add adaptive memory sizing from 2GB to 128GB+ systems

Breaking changes: None (backward compatible, deprecated lazy option ignored)

New APIs:
- getCacheStats(): Comprehensive cache performance statistics
- cachingStrategy field: Transparent strategy reporting
- Enhanced fairness metrics and memory pressure monitoring

Documentation:
- Add migration guide for v3.36.0
- Add operations/capacity-planning.md for enterprise deployments
- Update all examples and troubleshooting guides
- Rename monitor-lazy-mode.ts → monitor-cache-performance.ts
This commit is contained in:
David Snelling 2025-10-10 14:09:30 -07:00
parent 6037db3d85
commit 46c6af3f21
17 changed files with 2737 additions and 127 deletions

View file

@ -77,15 +77,10 @@ chmod 755 ./brainy-data
# Use custom writable path
const brain = new Brainy({
storage: {
adapter: 'filesystem',
type: 'filesystem',
path: '/tmp/brainy-data'
}
})
# Or use memory storage
const brain = new Brainy({
storage: { forceMemoryStorage: true }
})
```
### "ENOENT: no such file or directory"
@ -100,7 +95,7 @@ mkdir -p ./brainy-data
# Check storage configuration
const brain = new Brainy({
storage: {
adapter: 'filesystem',
type: 'filesystem',
path: '/full/path/to/storage' // Use absolute path
}
})
@ -280,11 +275,11 @@ const brain = new Brainy({
run: npm test
```
2. **Use memory storage in tests**
2. **Use temporary filesystem storage in tests**
```typescript
// In test setup
const brain = new Brainy({
storage: { forceMemoryStorage: true }
storage: { type: 'filesystem', path: '/tmp/brainy-test' }
})
```