safe-memory-layer 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -458,6 +458,69 @@ Works in all modern browsers that support:
|
|
|
458
458
|
|
|
459
459
|
No Node.js-specific APIs are used.
|
|
460
460
|
|
|
461
|
+
## Electron Support
|
|
462
|
+
|
|
463
|
+
Safe Memory Layer works perfectly in Electron applications, both in the main process and renderer process.
|
|
464
|
+
|
|
465
|
+
### Main Process
|
|
466
|
+
|
|
467
|
+
Use MemoryStore in Electron's main process for:
|
|
468
|
+
- Window state management
|
|
469
|
+
- IPC message caching
|
|
470
|
+
- Application state management
|
|
471
|
+
- Session data storage
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
import { MemoryStore } from "safe-memory-layer";
|
|
475
|
+
|
|
476
|
+
// Window state store
|
|
477
|
+
const windowStateStore = new MemoryStore<string, WindowState>({
|
|
478
|
+
defaultTTL: 5 * 60 * 1000, // 5 minutes
|
|
479
|
+
cleanupInterval: 30_000,
|
|
480
|
+
autoCleanup: true,
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
// Save window state
|
|
484
|
+
windowStateStore.set(`window:${windowId}`, {
|
|
485
|
+
bounds: window.getBounds(),
|
|
486
|
+
isFocused: window.isFocused(),
|
|
487
|
+
});
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Renderer Process
|
|
491
|
+
|
|
492
|
+
Use MemoryStore in Electron's renderer process (browser environment) for:
|
|
493
|
+
- UI component state
|
|
494
|
+
- API response caching
|
|
495
|
+
- DOM element metadata (with WeakMemoryStore)
|
|
496
|
+
- User preferences
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
import { MemoryStore, WeakMemoryStore } from "safe-memory-layer";
|
|
500
|
+
|
|
501
|
+
// UI state store
|
|
502
|
+
const uiStateStore = new MemoryStore<string, UIState>({
|
|
503
|
+
defaultTTL: 10 * 60 * 1000, // 10 minutes
|
|
504
|
+
autoCleanup: true,
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// DOM metadata store (auto-cleaned by GC)
|
|
508
|
+
const domStore = new WeakMemoryStore<ElementMetadata>();
|
|
509
|
+
|
|
510
|
+
const element = document.querySelector("#my-element");
|
|
511
|
+
domStore.set(element, { interactions: 0, lastClick: Date.now() });
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Electron Best Practices
|
|
515
|
+
|
|
516
|
+
1. **Dispose on app quit**: Always dispose stores when the app quits
|
|
517
|
+
2. **Use TTLs**: Set appropriate TTLs for cached data
|
|
518
|
+
3. **Separate stores**: Use different stores for different concerns
|
|
519
|
+
4. **Cleanup on window close**: Dispose stores when windows are closed
|
|
520
|
+
5. **IPC caching**: Cache IPC responses to reduce main process load
|
|
521
|
+
|
|
522
|
+
See the `examples/` directory for complete Electron examples.
|
|
523
|
+
|
|
461
524
|
## TypeScript Support
|
|
462
525
|
|
|
463
526
|
Full TypeScript support with generics:
|
|
@@ -498,4 +561,8 @@ npm test
|
|
|
498
561
|
- Event callbacks
|
|
499
562
|
- Statistics tracking
|
|
500
563
|
- Auto-dispose feature
|
|
501
|
-
- Full TypeScript support
|
|
564
|
+
- Full TypeScript support
|
|
565
|
+
|
|
566
|
+
### 1.1.0
|
|
567
|
+
|
|
568
|
+
- support Electron desktop (Framework)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "safe-memory-layer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Secure, lightweight, dependency-free in-memory storage with TTL support, automatic cleanup, and memory leak prevention for Node.js and browsers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|