@fjell/cache 4.6.21 → 4.7.0

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.
Files changed (52) hide show
  1. package/CACHE_IMPLEMENTATIONS.md +198 -0
  2. package/CONFIGURATION_GUIDE.md +167 -0
  3. package/CRITICAL_FIXES.md +68 -0
  4. package/README.md +506 -2
  5. package/debug_test2.js +0 -0
  6. package/debug_test3.js +0 -0
  7. package/dist/Cache.d.ts +4 -1
  8. package/dist/CacheContext.d.ts +27 -0
  9. package/dist/CacheMap.d.ts +89 -14
  10. package/dist/Instance.d.ts +4 -2
  11. package/dist/InstanceFactory.d.ts +3 -2
  12. package/dist/Operations.d.ts +2 -1
  13. package/dist/Options.d.ts +100 -0
  14. package/dist/browser/AsyncIndexDBCacheMap.d.ts +38 -0
  15. package/dist/browser/IndexDBCacheMap.d.ts +54 -0
  16. package/dist/browser/LocalStorageCacheMap.d.ts +43 -0
  17. package/dist/browser/SessionStorageCacheMap.d.ts +35 -0
  18. package/dist/eviction/EvictionStrategy.d.ts +50 -0
  19. package/dist/eviction/EvictionStrategyConfig.d.ts +97 -0
  20. package/dist/eviction/EvictionStrategyFactory.d.ts +12 -0
  21. package/dist/eviction/EvictionStrategyValidation.d.ts +36 -0
  22. package/dist/eviction/index.d.ts +9 -0
  23. package/dist/eviction/strategies/ARCEvictionStrategy.d.ts +68 -0
  24. package/dist/eviction/strategies/FIFOEvictionStrategy.d.ts +11 -0
  25. package/dist/eviction/strategies/LFUEvictionStrategy.d.ts +37 -0
  26. package/dist/eviction/strategies/LRUEvictionStrategy.d.ts +11 -0
  27. package/dist/eviction/strategies/MRUEvictionStrategy.d.ts +11 -0
  28. package/dist/eviction/strategies/RandomEvictionStrategy.d.ts +11 -0
  29. package/dist/eviction/strategies/TwoQueueEvictionStrategy.d.ts +53 -0
  30. package/dist/index.d.ts +24 -7
  31. package/dist/index.js +3879 -446
  32. package/dist/index.js.map +4 -4
  33. package/dist/memory/EnhancedMemoryCacheMap.d.ts +75 -0
  34. package/dist/memory/MemoryCacheMap.d.ts +33 -0
  35. package/dist/normalization.d.ts +20 -0
  36. package/dist/ops/action.d.ts +2 -3
  37. package/dist/ops/all.d.ts +2 -3
  38. package/dist/ops/allAction.d.ts +2 -3
  39. package/dist/ops/allFacet.d.ts +2 -3
  40. package/dist/ops/create.d.ts +2 -3
  41. package/dist/ops/facet.d.ts +2 -3
  42. package/dist/ops/find.d.ts +2 -3
  43. package/dist/ops/findOne.d.ts +2 -3
  44. package/dist/ops/get.d.ts +2 -3
  45. package/dist/ops/one.d.ts +2 -3
  46. package/dist/ops/remove.d.ts +2 -3
  47. package/dist/ops/reset.d.ts +2 -1
  48. package/dist/ops/retrieve.d.ts +2 -3
  49. package/dist/ops/set.d.ts +2 -2
  50. package/dist/ops/update.d.ts +2 -3
  51. package/dist/utils/CacheSize.d.ts +37 -0
  52. package/package.json +7 -7
package/README.md CHANGED
@@ -9,11 +9,18 @@ Fjell Cache provides intelligent caching capabilities for complex data models an
9
9
  ## Features
10
10
 
11
11
  - **Smart Caching**: Intelligent cache operations with automatic cache hits/misses
12
+ - **Multiple Cache Implementations**: In-memory, localStorage, sessionStorage, and IndexedDB support
13
+ - **Comprehensive Configuration**: Rich options system for performance tuning and environment optimization
12
14
  - **Business Relationships**: Automatic population of related entities through aggregation
13
15
  - **Performance Optimized**: High-performance cache operations with bulk processing
16
+ - **Environment Aware**: Automatic environment detection with fallback strategies
14
17
  - **Location-Based**: Support for contained items with location hierarchies
18
+ - **Browser-Ready**: Native browser storage implementations for client-side caching
15
19
  - **Framework Integration**: Seamless integration with Fjell Core, Registry, and Client API
16
20
  - **TypeScript First**: Full TypeScript support with comprehensive type safety
21
+ - **Cache Size Limits**: Configure maximum cache size in bytes or item count with automatic eviction
22
+ - **Advanced Eviction Policies**: LRU, LFU, FIFO, MRU, Random, ARC, and 2Q strategies for optimal performance
23
+ - **Performance Monitoring**: Built-in cache statistics and utilization tracking
17
24
 
18
25
  ## Installation
19
26
 
@@ -28,7 +35,7 @@ yarn add @fjell/cache
28
35
  ## Quick Start
29
36
 
30
37
  ```typescript
31
- import { createCache } from '@fjell/cache';
38
+ import { createCache, MemoryCacheMap } from '@fjell/cache';
32
39
  import { createCoordinate, createRegistry } from '@fjell/registry';
33
40
  import { ClientApi } from '@fjell/client-api';
34
41
 
@@ -45,6 +52,437 @@ const [, cachedUser] = await userCache.operations.get(userKey);
45
52
  const [, retrievedUser] = await userCache.operations.retrieve(userKey); // Cache hit!
46
53
 
47
54
  await userCache.operations.set(userKey, updatedUser);
55
+
56
+ // Or use cache implementations directly
57
+ const memoryCache = new MemoryCacheMap<User>(['user']);
58
+ memoryCache.set(userKey, user);
59
+ const cachedUser = memoryCache.get(userKey);
60
+ ```
61
+
62
+ ## Configuration Options
63
+
64
+ Fjell Cache provides comprehensive configuration options to optimize caching behavior for your specific environment and performance requirements.
65
+
66
+ ### Basic Configuration
67
+
68
+ ```typescript
69
+ import { createInstanceFactory, createCache, Options } from '@fjell/cache';
70
+
71
+ // Configure cache with options
72
+ const options: Partial<Options<User, 'user'>> = {
73
+ cacheType: 'memory',
74
+ enableDebugLogging: true,
75
+ autoSync: true,
76
+ maxRetries: 3,
77
+ retryDelay: 1000,
78
+ ttl: 300000 // 5 minutes
79
+ };
80
+
81
+ // Use with InstanceFactory (recommended)
82
+ const factory = createInstanceFactory(userApi, options);
83
+ const cache = factory(coordinate, { registry });
84
+
85
+ // Or directly with createCache
86
+ const cache = createCache(userApi, coordinate, registry, options);
87
+ ```
88
+
89
+ ### Cache Types
90
+
91
+ #### Memory Cache (Default)
92
+ Fast in-memory caching with optional size limits, TTL, and advanced eviction policies:
93
+
94
+ ```typescript
95
+ const options: Partial<Options<User, 'user'>> = {
96
+ cacheType: 'memory',
97
+ memoryConfig: {
98
+ maxItems: 1000, // Maximum number of items to cache
99
+ ttl: 300000, // Time-to-live in milliseconds (5 minutes)
100
+ size: {
101
+ maxSizeBytes: '10MB', // Maximum cache size in bytes
102
+ maxItems: 1000, // Alternative/additional item limit
103
+ evictionPolicy: 'lru' // Eviction strategy when limits exceeded
104
+ }
105
+ }
106
+ };
107
+ ```
108
+
109
+ #### Browser localStorage (Persistent)
110
+ Persistent storage that survives page reloads and browser restarts:
111
+
112
+ ```typescript
113
+ const options: Partial<Options<User, 'user'>> = {
114
+ cacheType: 'localStorage',
115
+ webStorageConfig: {
116
+ keyPrefix: 'myapp:users:', // Namespace your cache keys
117
+ compress: false // Enable/disable compression
118
+ }
119
+ };
120
+ ```
121
+
122
+ #### Browser sessionStorage (Session-only)
123
+ Session-based storage that's cleared when the tab closes:
124
+
125
+ ```typescript
126
+ const options: Partial<Options<User, 'user'>> = {
127
+ cacheType: 'sessionStorage',
128
+ webStorageConfig: {
129
+ keyPrefix: 'session:users:',
130
+ compress: true // Compress data to save space
131
+ }
132
+ };
133
+ ```
134
+
135
+ #### IndexedDB (Large-scale, Synchronous)
136
+ For large amounts of structured data with synchronous API:
137
+
138
+ ```typescript
139
+ const options: Partial<Options<User, 'user'>> = {
140
+ cacheType: 'indexedDB',
141
+ indexedDBConfig: {
142
+ dbName: 'MyAppCache', // Database name
143
+ version: 2, // Database version
144
+ storeName: 'users' // Object store name
145
+ }
146
+ };
147
+ ```
148
+
149
+ #### IndexedDB (Large-scale, Asynchronous)
150
+ Recommended IndexedDB implementation with full async support:
151
+
152
+ ```typescript
153
+ const options: Partial<Options<User, 'user'>> = {
154
+ cacheType: 'indexedDB',
155
+ indexedDBConfig: {
156
+ dbName: 'MyAppCache',
157
+ version: 1,
158
+ storeName: 'userData'
159
+ }
160
+ };
161
+
162
+ // Access async operations via the asyncCache property
163
+ const cache = createCache(api, coordinate, options);
164
+ const asyncValue = await cache.cacheMap.asyncCache.get(key);
165
+ await cache.cacheMap.asyncCache.set(key, value);
166
+ ```
167
+
168
+ #### Custom Cache Implementation
169
+ Bring your own cache implementation:
170
+
171
+ ```typescript
172
+ import { CacheMap } from '@fjell/cache';
173
+
174
+ const customCacheFactory = (kta) => {
175
+ // Return your custom CacheMap implementation
176
+ return new MyCustomCacheMap(kta);
177
+ };
178
+
179
+ const options: Partial<Options<User, 'user'>> = {
180
+ cacheType: 'custom',
181
+ customCacheMapFactory: customCacheFactory
182
+ };
183
+ ```
184
+
185
+ ### Cache Size Limits and Eviction Policies
186
+
187
+ Fjell Cache supports sophisticated cache size management with automatic eviction when limits are exceeded. You can configure both byte-based and item-count-based limits, along with various eviction strategies to optimize performance for your specific use case.
188
+
189
+ #### Size Configuration
190
+
191
+ Configure cache limits using flexible size formats:
192
+
193
+ ```typescript
194
+ const options: Partial<Options<User, 'user'>> = {
195
+ cacheType: 'memory',
196
+ memoryConfig: {
197
+ size: {
198
+ // Byte-based limits (decimal units)
199
+ maxSizeBytes: '10MB', // 10 megabytes
200
+ maxSizeBytes: '500KB', // 500 kilobytes
201
+ maxSizeBytes: '2GB', // 2 gigabytes
202
+
203
+ // Byte-based limits (binary units)
204
+ maxSizeBytes: '10MiB', // 10 mebibytes (1024^2)
205
+ maxSizeBytes: '500KiB', // 500 kibibytes (1024)
206
+ maxSizeBytes: '2GiB', // 2 gibibytes (1024^3)
207
+
208
+ // Raw bytes
209
+ maxSizeBytes: '1048576', // 1MB in bytes
210
+
211
+ // Item count limit
212
+ maxItems: 1000, // Maximum number of cached items
213
+
214
+ // Eviction policy (required when limits are set)
215
+ evictionPolicy: 'lru' // Strategy for removing items
216
+ }
217
+ }
218
+ };
219
+ ```
220
+
221
+ #### Eviction Policies
222
+
223
+ Choose from several battle-tested eviction strategies:
224
+
225
+ ##### LRU (Least Recently Used) - Default
226
+ Removes the item that was accessed longest ago. Best general-purpose strategy.
227
+
228
+ ```typescript
229
+ const options: Partial<Options<User, 'user'>> = {
230
+ cacheType: 'memory',
231
+ memoryConfig: {
232
+ size: {
233
+ maxItems: 1000,
234
+ evictionPolicy: 'lru' // Remove least recently accessed items
235
+ }
236
+ }
237
+ };
238
+ ```
239
+
240
+ ##### LFU (Least Frequently Used)
241
+ Removes the item with the lowest access count. Good for workloads with stable access patterns.
242
+
243
+ ```typescript
244
+ const options: Partial<Options<User, 'user'>> = {
245
+ cacheType: 'memory',
246
+ memoryConfig: {
247
+ size: {
248
+ maxItems: 1000,
249
+ evictionPolicy: 'lfu' // Remove least frequently accessed items
250
+ }
251
+ }
252
+ };
253
+ ```
254
+
255
+ ##### FIFO (First-In, First-Out)
256
+ Removes the oldest added item regardless of usage. Simple and predictable.
257
+
258
+ ```typescript
259
+ const options: Partial<Options<User, 'user'>> = {
260
+ cacheType: 'memory',
261
+ memoryConfig: {
262
+ size: {
263
+ maxItems: 1000,
264
+ evictionPolicy: 'fifo' // Remove oldest items first
265
+ }
266
+ }
267
+ };
268
+ ```
269
+
270
+ ##### MRU (Most Recently Used)
271
+ Removes the most recently accessed item. Useful for specific access patterns.
272
+
273
+ ```typescript
274
+ const options: Partial<Options<User, 'user'>> = {
275
+ cacheType: 'memory',
276
+ memoryConfig: {
277
+ size: {
278
+ maxItems: 1000,
279
+ evictionPolicy: 'mru' // Remove most recently accessed items
280
+ }
281
+ }
282
+ };
283
+ ```
284
+
285
+ ##### Random Replacement
286
+ Evicts a random item. Fast and low-overhead for uniform workloads.
287
+
288
+ ```typescript
289
+ const options: Partial<Options<User, 'user'>> = {
290
+ cacheType: 'memory',
291
+ memoryConfig: {
292
+ size: {
293
+ maxItems: 1000,
294
+ evictionPolicy: 'random' // Remove random items
295
+ }
296
+ }
297
+ };
298
+ ```
299
+
300
+ ##### ARC (Adaptive Replacement Cache)
301
+ Balances between recency (LRU) and frequency (LFU) dynamically. Adapts to workload patterns.
302
+
303
+ ```typescript
304
+ const options: Partial<Options<User, 'user'>> = {
305
+ cacheType: 'memory',
306
+ memoryConfig: {
307
+ size: {
308
+ maxItems: 1000,
309
+ evictionPolicy: 'arc' // Adaptive replacement cache
310
+ }
311
+ }
312
+ };
313
+ ```
314
+
315
+ ##### 2Q (Two Queues)
316
+ Maintains separate queues for recent and frequently accessed items. Reduces cache pollution.
317
+
318
+ ```typescript
319
+ const options: Partial<Options<User, 'user'>> = {
320
+ cacheType: 'memory',
321
+ memoryConfig: {
322
+ size: {
323
+ maxItems: 1000,
324
+ evictionPolicy: '2q' // Two-queue algorithm
325
+ }
326
+ }
327
+ };
328
+ ```
329
+
330
+ #### Combined Size and Item Limits
331
+
332
+ You can specify both size and item limits. The cache will respect whichever limit is reached first:
333
+
334
+ ```typescript
335
+ const options: Partial<Options<User, 'user'>> = {
336
+ cacheType: 'memory',
337
+ memoryConfig: {
338
+ size: {
339
+ maxSizeBytes: '50MB', // Size limit
340
+ maxItems: 10000, // Item count limit
341
+ evictionPolicy: 'lru' // Eviction strategy
342
+ }
343
+ }
344
+ };
345
+ ```
346
+
347
+ #### Performance Monitoring
348
+
349
+ Monitor cache performance and utilization:
350
+
351
+ ```typescript
352
+ import { createCache, formatBytes } from '@fjell/cache';
353
+
354
+ const cache = createCache(/* ... */);
355
+
356
+ // Get cache statistics
357
+ const stats = cache.getStats();
358
+ console.log(`Items: ${stats.currentItemCount}/${stats.maxItems}`);
359
+ console.log(`Size: ${formatBytes(stats.currentSizeBytes)}/${formatBytes(stats.maxSizeBytes)}`);
360
+ console.log(`Item utilization: ${stats.utilizationPercent.items?.toFixed(1)}%`);
361
+ console.log(`Size utilization: ${stats.utilizationPercent.bytes?.toFixed(1)}%`);
362
+ ```
363
+
364
+ ### Performance and Reliability Options
365
+
366
+ Configure retry logic, synchronization, and debugging:
367
+
368
+ ```typescript
369
+ const options: Partial<Options<User, 'user'>> = {
370
+ // Retry configuration
371
+ maxRetries: 5, // Number of retry attempts
372
+ retryDelay: 2000, // Delay between retries (ms)
373
+
374
+ // Synchronization
375
+ autoSync: true, // Auto-sync with API
376
+ ttl: 600000, // Default expiration (10 minutes)
377
+
378
+ // Debugging
379
+ enableDebugLogging: true // Enable detailed debug logs
380
+ };
381
+ ```
382
+
383
+ ### Environment-based Configuration
384
+
385
+ Automatically adapt cache strategy based on environment:
386
+
387
+ ```typescript
388
+ const getOptimalCacheOptions = (): Partial<Options<User, 'user'>> => {
389
+ // Browser environment with IndexedDB support
390
+ if (typeof window !== 'undefined' && 'indexedDB' in window) {
391
+ return {
392
+ cacheType: 'indexedDB',
393
+ indexedDBConfig: {
394
+ dbName: 'MyAppCache',
395
+ version: 1,
396
+ storeName: 'users'
397
+ },
398
+ enableDebugLogging: false
399
+ };
400
+ }
401
+
402
+ // Browser environment with localStorage
403
+ if (typeof window !== 'undefined' && 'localStorage' in window) {
404
+ return {
405
+ cacheType: 'localStorage',
406
+ webStorageConfig: {
407
+ keyPrefix: 'myapp:',
408
+ compress: true
409
+ }
410
+ };
411
+ }
412
+
413
+ // Node.js or other environments - use memory
414
+ return {
415
+ cacheType: 'memory',
416
+ memoryConfig: {
417
+ maxItems: 5000,
418
+ ttl: 300000
419
+ },
420
+ enableDebugLogging: true
421
+ };
422
+ };
423
+
424
+ const factory = createInstanceFactory(userApi, getOptimalCacheOptions());
425
+ ```
426
+
427
+ ### Complete Options Reference
428
+
429
+ ```typescript
430
+ interface Options<V extends Item<S>, S extends string> {
431
+ // Cache type selection
432
+ cacheType: 'memory' | 'localStorage' | 'sessionStorage' |
433
+ 'indexedDB' | 'custom';
434
+
435
+ // Memory cache configuration
436
+ memoryConfig?: {
437
+ maxItems?: number; // Maximum items to store
438
+ ttl?: number; // Time-to-live in milliseconds
439
+ };
440
+
441
+ // Web storage configuration (localStorage/sessionStorage)
442
+ webStorageConfig?: {
443
+ keyPrefix?: string; // Key prefix for namespacing
444
+ compress?: boolean; // Enable compression
445
+ };
446
+
447
+ // IndexedDB configuration
448
+ indexedDBConfig?: {
449
+ dbName?: string; // Database name
450
+ version?: number; // Database version
451
+ storeName?: string; // Object store name
452
+ };
453
+
454
+ // Custom cache factory
455
+ customCacheMapFactory?: (kta: AllItemTypeArrays) => CacheMap;
456
+
457
+ // Performance and reliability
458
+ maxRetries?: number; // Retry attempts (default: 3)
459
+ retryDelay?: number; // Retry delay in ms (default: 1000)
460
+ autoSync?: boolean; // Auto-sync with API (default: true)
461
+ ttl?: number; // Default expiration in ms
462
+ enableDebugLogging?: boolean; // Debug logging (default: false)
463
+ }
464
+ ```
465
+
466
+ ### Validation and Error Handling
467
+
468
+ The Options system includes automatic validation:
469
+
470
+ - **Environment Checks**: Validates browser API availability
471
+ - **Configuration Validation**: Ensures required options are provided
472
+ - **Type Safety**: Full TypeScript support with compile-time checks
473
+ - **Runtime Errors**: Clear error messages for invalid configurations
474
+
475
+ ```typescript
476
+ // This will throw a clear error in Node.js environment:
477
+ const options = { cacheType: 'localStorage' as const };
478
+ // Error: localStorage is not available in non-browser environments
479
+
480
+ // This will throw an error:
481
+ const options = {
482
+ cacheType: 'custom' as const
483
+ // Missing: customCacheMapFactory
484
+ };
485
+ // Error: customCacheMapFactory is required when cacheType is "custom"
48
486
  ```
49
487
 
50
488
  ## Core Components
@@ -59,19 +497,84 @@ await userCache.operations.set(userKey, updatedUser);
59
497
  - **Required vs Optional**: Flexible relationship management
60
498
  - **Business Logic**: Complex business scenarios with interconnected data
61
499
 
500
+ ### Cache Implementations
501
+ - **MemoryCacheMap**: Fast in-memory caching (default)
502
+ - **LocalStorageCacheMap**: Persistent browser caching with localStorage
503
+ - **SessionStorageCacheMap**: Session-based browser caching with sessionStorage
504
+ - **AsyncIndexDBCacheMap**: Large-scale browser caching with IndexedDB
505
+ - **IndexDBCacheMap**: Synchronous wrapper for IndexedDB (throws errors, use async version)
506
+
62
507
  ### Direct Cache Management
63
- - **CacheMap**: Low-level cache operations and management
508
+ - **CacheMap Interface**: Abstract interface for all cache implementations
64
509
  - **Location Filtering**: Filter contained items by location hierarchy
65
510
  - **Bulk Operations**: Efficient processing of multiple cache operations
511
+ - **Key Normalization**: Consistent string/number key handling across implementations
66
512
 
67
513
  ## Examples
68
514
 
69
515
  Comprehensive examples are available in the [examples directory](./examples/):
70
516
 
71
517
  - **[Basic Cache Example](./examples/basic-cache-example.ts)** - Start here! Fundamental caching operations
518
+ - **[Cache Configuration Example](./examples/cache-configuration-example.ts)** - Complete guide to cache options and configuration
519
+ - **[Cache Type Configurations Example](./examples/cache-type-configurations-example.ts)** - Practical setup for Memory, IndexedDB, and localStorage
72
520
  - **[Aggregator Example](./examples/aggregator-example.ts)** - Advanced business relationships
73
521
  - **[Cache Map Example](./examples/cache-map-example.ts)** - Low-level cache operations
74
522
 
523
+ ## Browser Cache Implementations
524
+
525
+ Fjell Cache provides multiple cache implementations optimized for different environments:
526
+
527
+ ### In-Memory Caching (Default)
528
+ ```typescript
529
+ import { MemoryCacheMap } from '@fjell/cache';
530
+
531
+ const cache = new MemoryCacheMap<MyItem>(['myitem']);
532
+ cache.set(key, item);
533
+ const item = cache.get(key);
534
+ ```
535
+
536
+ ### Browser localStorage (Persistent)
537
+ ```typescript
538
+ import { LocalStorageCacheMap } from '@fjell/cache';
539
+
540
+ // Survives page reloads and browser restarts
541
+ const cache = new LocalStorageCacheMap<MyItem>(['myitem'], 'my-app-cache');
542
+ cache.set(key, item);
543
+ const item = cache.get(key); // Retrieved from localStorage
544
+ ```
545
+
546
+ ### Browser sessionStorage (Session-only)
547
+ ```typescript
548
+ import { SessionStorageCacheMap } from '@fjell/cache';
549
+
550
+ // Lost when tab is closed
551
+ const cache = new SessionStorageCacheMap<MyItem>(['myitem'], 'session-cache');
552
+ cache.set(key, item);
553
+ const item = cache.get(key); // Retrieved from sessionStorage
554
+ ```
555
+
556
+ ### IndexedDB (Large-scale, Asynchronous)
557
+ ```typescript
558
+ import { AsyncIndexDBCacheMap } from '@fjell/cache';
559
+
560
+ // For large amounts of structured data
561
+ const cache = new AsyncIndexDBCacheMap<MyItem>(['myitem'], 'MyAppDB', 'items', 1);
562
+
563
+ // All operations are async
564
+ await cache.set(key, item);
565
+ const item = await cache.get(key);
566
+ const allItems = await cache.values();
567
+ ```
568
+
569
+ ### Cache Implementation Comparison
570
+
571
+ | Implementation | Storage | Persistence | Size Limit | Sync/Async | Use Case |
572
+ |---|---|---|---|---|---|
573
+ | MemoryCacheMap | Memory | None | RAM | Sync | Default, fast access |
574
+ | LocalStorageCacheMap | localStorage | Permanent | ~5-10MB | Sync | User preferences, settings |
575
+ | SessionStorageCacheMap | sessionStorage | Session only | ~5MB | Sync | Temporary session data |
576
+ | AsyncIndexDBCacheMap | IndexedDB | Permanent | Hundreds of MB+ | Async | Large datasets, offline apps |
577
+
75
578
  ## Documentation
76
579
 
77
580
  For detailed documentation, examples, and API reference, visit our [documentation site](https://getfjell.github.io/fjell-cache/).
@@ -94,3 +597,4 @@ Apache-2.0
94
597
  We welcome contributions! Please see our contributing guidelines for more information.
95
598
 
96
599
  Built with love by the Fjell team.
600
+ # Test fix for sendit config bug
package/debug_test2.js ADDED
File without changes
package/debug_test3.js ADDED
File without changes
package/dist/Cache.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Instance as BaseInstance, Coordinate, Registry } from "@fjell/registry"
3
3
  import { ClientApi } from "@fjell/client-api";
4
4
  import { CacheMap } from "./CacheMap";
5
5
  import { Operations } from "./Operations";
6
+ import { Options } from "./Options";
6
7
  /**
7
8
  * The Cache interface extends the base Instance from @fjell/registry and adds cache operations
8
9
  * for interacting with cached data.
@@ -23,6 +24,8 @@ export interface Cache<V extends Item<S, L1, L2, L3, L4, L5>, S extends string,
23
24
  cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
24
25
  /** All cache operations that work with both cache and API */
25
26
  operations: Operations<V, S, L1, L2, L3, L4, L5>;
27
+ /** Cache configuration options */
28
+ options?: Options<V, S, L1, L2, L3, L4, L5>;
26
29
  }
27
- export declare const createCache: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, registry: Registry) => Cache<V, S, L1, L2, L3, L4, L5>;
30
+ export declare const createCache: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, registry: Registry, options?: Partial<Options<V, S, L1, L2, L3, L4, L5>>) => Cache<V, S, L1, L2, L3, L4, L5>;
28
31
  export declare const isCache: (cache: any) => cache is Cache<any, any, any, any, any, any, any>;
@@ -0,0 +1,27 @@
1
+ import { Item } from "@fjell/core";
2
+ import { ClientApi } from "@fjell/client-api";
3
+ import { CacheMap } from "./CacheMap";
4
+ import { Options } from "./Options";
5
+ /**
6
+ * Context object that consolidates all cache-related parameters
7
+ * passed to cache operations. This prevents cache concerns from
8
+ * polluting operation signatures.
9
+ */
10
+ export interface CacheContext<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
11
+ /** The client API for making requests */
12
+ api: ClientApi<V, S, L1, L2, L3, L4, L5>;
13
+ /** The cache map for storing and retrieving cached items */
14
+ cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
15
+ /** The primary key type */
16
+ pkType: S;
17
+ /** Cache options including TTL configuration */
18
+ options: Options<V, S, L1, L2, L3, L4, L5>;
19
+ /** TTL for individual items (from memoryConfig.ttl or ttl) */
20
+ itemTtl?: number;
21
+ /** TTL for query results (from ttl) */
22
+ queryTtl?: number;
23
+ }
24
+ /**
25
+ * Creates a CacheContext from the individual cache-related parameters
26
+ */
27
+ export declare const createCacheContext: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>, pkType: S, options: Options<V, S, L1, L2, L3, L4, L5>) => CacheContext<V, S, L1, L2, L3, L4, L5>;