@coherent.js/performance 1.0.0-beta.5 → 1.0.0-beta.7
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/dist/cache.js +417 -0
- package/dist/cache.js.map +7 -0
- package/dist/code-splitting.js +313 -0
- package/dist/code-splitting.js.map +7 -0
- package/dist/index.js.map +7 -0
- package/dist/lazy-loading.js +332 -0
- package/dist/lazy-loading.js.map +7 -0
- package/package.json +13 -3
- package/types/index.d.ts +426 -29
package/dist/cache.js
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// src/cache.js
|
|
2
|
+
var LRUCache = class {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.maxSize = options.maxSize || 100;
|
|
5
|
+
this.ttl = options.ttl || null;
|
|
6
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
7
|
+
this.accessOrder = [];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get value from cache
|
|
11
|
+
*/
|
|
12
|
+
get(key) {
|
|
13
|
+
if (!this.cache.has(key)) {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
const entry = this.cache.get(key);
|
|
17
|
+
if (this.ttl && Date.now() - entry.timestamp > this.ttl) {
|
|
18
|
+
this.delete(key);
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
this.updateAccessOrder(key);
|
|
22
|
+
return entry.value;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Set value in cache
|
|
26
|
+
*/
|
|
27
|
+
set(key, value) {
|
|
28
|
+
if (this.cache.has(key)) {
|
|
29
|
+
this.delete(key);
|
|
30
|
+
}
|
|
31
|
+
if (this.cache.size >= this.maxSize) {
|
|
32
|
+
this.evict();
|
|
33
|
+
}
|
|
34
|
+
this.cache.set(key, {
|
|
35
|
+
value,
|
|
36
|
+
timestamp: Date.now()
|
|
37
|
+
});
|
|
38
|
+
this.accessOrder.push(key);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if key exists
|
|
43
|
+
*/
|
|
44
|
+
has(key) {
|
|
45
|
+
if (!this.cache.has(key)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const entry = this.cache.get(key);
|
|
49
|
+
if (this.ttl && Date.now() - entry.timestamp > this.ttl) {
|
|
50
|
+
this.delete(key);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Delete key
|
|
57
|
+
*/
|
|
58
|
+
delete(key) {
|
|
59
|
+
this.cache.delete(key);
|
|
60
|
+
const index = this.accessOrder.indexOf(key);
|
|
61
|
+
if (index > -1) {
|
|
62
|
+
this.accessOrder.splice(index, 1);
|
|
63
|
+
}
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clear cache
|
|
68
|
+
*/
|
|
69
|
+
clear() {
|
|
70
|
+
this.cache.clear();
|
|
71
|
+
this.accessOrder = [];
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get cache size
|
|
76
|
+
*/
|
|
77
|
+
size() {
|
|
78
|
+
return this.cache.size;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Update access order
|
|
82
|
+
*/
|
|
83
|
+
updateAccessOrder(key) {
|
|
84
|
+
const index = this.accessOrder.indexOf(key);
|
|
85
|
+
if (index > -1) {
|
|
86
|
+
this.accessOrder.splice(index, 1);
|
|
87
|
+
}
|
|
88
|
+
this.accessOrder.push(key);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Evict least recently used
|
|
92
|
+
*/
|
|
93
|
+
evict() {
|
|
94
|
+
if (this.accessOrder.length > 0) {
|
|
95
|
+
const oldest = this.accessOrder.shift();
|
|
96
|
+
this.cache.delete(oldest);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get all keys
|
|
101
|
+
*/
|
|
102
|
+
keys() {
|
|
103
|
+
return Array.from(this.cache.keys());
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get all values
|
|
107
|
+
*/
|
|
108
|
+
values() {
|
|
109
|
+
return Array.from(this.cache.values()).map((entry) => entry.value);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get statistics
|
|
113
|
+
*/
|
|
114
|
+
getStats() {
|
|
115
|
+
return {
|
|
116
|
+
size: this.cache.size,
|
|
117
|
+
maxSize: this.maxSize,
|
|
118
|
+
utilizationPercent: (this.cache.size / this.maxSize * 100).toFixed(2),
|
|
119
|
+
oldestKey: this.accessOrder[0],
|
|
120
|
+
newestKey: this.accessOrder[this.accessOrder.length - 1]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var MemoryCache = class {
|
|
125
|
+
constructor(options = {}) {
|
|
126
|
+
this.options = {
|
|
127
|
+
strategy: "lru",
|
|
128
|
+
// lru, lfu, fifo
|
|
129
|
+
maxSize: 100,
|
|
130
|
+
ttl: null,
|
|
131
|
+
...options
|
|
132
|
+
};
|
|
133
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
134
|
+
this.metadata = /* @__PURE__ */ new Map();
|
|
135
|
+
this.hits = 0;
|
|
136
|
+
this.misses = 0;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get from cache
|
|
140
|
+
*/
|
|
141
|
+
get(key) {
|
|
142
|
+
if (!this.cache.has(key)) {
|
|
143
|
+
this.misses++;
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
const entry = this.cache.get(key);
|
|
147
|
+
if (entry.ttl && Date.now() > entry.expiresAt) {
|
|
148
|
+
this.delete(key);
|
|
149
|
+
this.misses++;
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
this.updateMetadata(key);
|
|
153
|
+
this.hits++;
|
|
154
|
+
return entry.value;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Set in cache
|
|
158
|
+
*/
|
|
159
|
+
set(key, value, options = {}) {
|
|
160
|
+
if (this.cache.size >= this.options.maxSize && !this.cache.has(key)) {
|
|
161
|
+
this.evict();
|
|
162
|
+
}
|
|
163
|
+
const ttl = options.ttl || this.options.ttl;
|
|
164
|
+
this.cache.set(key, {
|
|
165
|
+
value,
|
|
166
|
+
ttl,
|
|
167
|
+
expiresAt: ttl ? Date.now() + ttl : null,
|
|
168
|
+
createdAt: Date.now()
|
|
169
|
+
});
|
|
170
|
+
this.metadata.set(key, {
|
|
171
|
+
accessCount: 0,
|
|
172
|
+
lastAccess: Date.now()
|
|
173
|
+
});
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Update metadata based on strategy
|
|
178
|
+
*/
|
|
179
|
+
updateMetadata(key) {
|
|
180
|
+
const meta = this.metadata.get(key);
|
|
181
|
+
if (meta) {
|
|
182
|
+
meta.accessCount++;
|
|
183
|
+
meta.lastAccess = Date.now();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Evict based on strategy
|
|
188
|
+
*/
|
|
189
|
+
evict() {
|
|
190
|
+
let keyToEvict;
|
|
191
|
+
switch (this.options.strategy) {
|
|
192
|
+
case "lru":
|
|
193
|
+
keyToEvict = this.findLRU();
|
|
194
|
+
break;
|
|
195
|
+
case "lfu":
|
|
196
|
+
keyToEvict = this.findLFU();
|
|
197
|
+
break;
|
|
198
|
+
case "fifo":
|
|
199
|
+
keyToEvict = this.findFIFO();
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
keyToEvict = this.cache.keys().next().value;
|
|
203
|
+
}
|
|
204
|
+
if (keyToEvict) {
|
|
205
|
+
this.delete(keyToEvict);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Find least recently used key
|
|
210
|
+
*/
|
|
211
|
+
findLRU() {
|
|
212
|
+
let oldest = null;
|
|
213
|
+
let oldestTime = Infinity;
|
|
214
|
+
for (const [key, meta] of this.metadata.entries()) {
|
|
215
|
+
if (meta.lastAccess < oldestTime) {
|
|
216
|
+
oldestTime = meta.lastAccess;
|
|
217
|
+
oldest = key;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return oldest;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Find least frequently used key
|
|
224
|
+
*/
|
|
225
|
+
findLFU() {
|
|
226
|
+
let leastUsed = null;
|
|
227
|
+
let minCount = Infinity;
|
|
228
|
+
for (const [key, meta] of this.metadata.entries()) {
|
|
229
|
+
if (meta.accessCount < minCount) {
|
|
230
|
+
minCount = meta.accessCount;
|
|
231
|
+
leastUsed = key;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return leastUsed;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Find first in (oldest)
|
|
238
|
+
*/
|
|
239
|
+
findFIFO() {
|
|
240
|
+
let oldest = null;
|
|
241
|
+
let oldestTime = Infinity;
|
|
242
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
243
|
+
if (entry.createdAt < oldestTime) {
|
|
244
|
+
oldestTime = entry.createdAt;
|
|
245
|
+
oldest = key;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return oldest;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Check if key exists
|
|
252
|
+
*/
|
|
253
|
+
has(key) {
|
|
254
|
+
return this.cache.has(key);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Delete key
|
|
258
|
+
*/
|
|
259
|
+
delete(key) {
|
|
260
|
+
this.cache.delete(key);
|
|
261
|
+
this.metadata.delete(key);
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Clear cache
|
|
266
|
+
*/
|
|
267
|
+
clear() {
|
|
268
|
+
this.cache.clear();
|
|
269
|
+
this.metadata.clear();
|
|
270
|
+
this.hits = 0;
|
|
271
|
+
this.misses = 0;
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get cache statistics
|
|
276
|
+
*/
|
|
277
|
+
getStats() {
|
|
278
|
+
const total = this.hits + this.misses;
|
|
279
|
+
const hitRate = total > 0 ? (this.hits / total * 100).toFixed(2) : 0;
|
|
280
|
+
return {
|
|
281
|
+
size: this.cache.size,
|
|
282
|
+
maxSize: this.options.maxSize,
|
|
283
|
+
hits: this.hits,
|
|
284
|
+
misses: this.misses,
|
|
285
|
+
hitRate: `${hitRate}%`,
|
|
286
|
+
strategy: this.options.strategy
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var MemoCache = class {
|
|
291
|
+
constructor(options = {}) {
|
|
292
|
+
this.cache = new LRUCache(options);
|
|
293
|
+
this.keyGenerator = options.keyGenerator || this.defaultKeyGenerator;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Default key generator
|
|
297
|
+
*/
|
|
298
|
+
defaultKeyGenerator(...args) {
|
|
299
|
+
return JSON.stringify(args);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Memoize a function
|
|
303
|
+
*/
|
|
304
|
+
memoize(fn) {
|
|
305
|
+
return (...args) => {
|
|
306
|
+
const key = this.keyGenerator(...args);
|
|
307
|
+
if (this.cache.has(key)) {
|
|
308
|
+
return this.cache.get(key);
|
|
309
|
+
}
|
|
310
|
+
const result = fn(...args);
|
|
311
|
+
this.cache.set(key, result);
|
|
312
|
+
return result;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Clear memoization cache
|
|
317
|
+
*/
|
|
318
|
+
clear() {
|
|
319
|
+
this.cache.clear();
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get statistics
|
|
323
|
+
*/
|
|
324
|
+
getStats() {
|
|
325
|
+
return this.cache.getStats();
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var RenderCache = class {
|
|
329
|
+
constructor(options = {}) {
|
|
330
|
+
this.cache = new MemoryCache({
|
|
331
|
+
maxSize: options.maxSize || 50,
|
|
332
|
+
ttl: options.ttl || 6e4,
|
|
333
|
+
// 1 minute default
|
|
334
|
+
strategy: "lru"
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Generate cache key for component
|
|
339
|
+
*/
|
|
340
|
+
generateKey(component, props) {
|
|
341
|
+
const componentName = component.name || "anonymous";
|
|
342
|
+
const propsKey = this.hashProps(props);
|
|
343
|
+
return `${componentName}:${propsKey}`;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Hash props for cache key
|
|
347
|
+
*/
|
|
348
|
+
hashProps(props) {
|
|
349
|
+
try {
|
|
350
|
+
return JSON.stringify(props, Object.keys(props).sort());
|
|
351
|
+
} catch {
|
|
352
|
+
return String(Date.now());
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get cached render
|
|
357
|
+
*/
|
|
358
|
+
get(component, props) {
|
|
359
|
+
const key = this.generateKey(component, props);
|
|
360
|
+
return this.cache.get(key);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Cache render result
|
|
364
|
+
*/
|
|
365
|
+
set(component, props, result, options = {}) {
|
|
366
|
+
const key = this.generateKey(component, props);
|
|
367
|
+
this.cache.set(key, result, options);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Clear cache
|
|
371
|
+
*/
|
|
372
|
+
clear() {
|
|
373
|
+
this.cache.clear();
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Get statistics
|
|
377
|
+
*/
|
|
378
|
+
getStats() {
|
|
379
|
+
return this.cache.getStats();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function createCache(type = "lru", options = {}) {
|
|
383
|
+
switch (type) {
|
|
384
|
+
case "lru":
|
|
385
|
+
return new LRUCache(options);
|
|
386
|
+
case "memory":
|
|
387
|
+
return new MemoryCache(options);
|
|
388
|
+
case "memo":
|
|
389
|
+
return new MemoCache(options);
|
|
390
|
+
case "render":
|
|
391
|
+
return new RenderCache(options);
|
|
392
|
+
default:
|
|
393
|
+
return new LRUCache(options);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function memoize(fn, options = {}) {
|
|
397
|
+
const cache = new MemoCache(options);
|
|
398
|
+
return cache.memoize(fn);
|
|
399
|
+
}
|
|
400
|
+
var cache_default = {
|
|
401
|
+
LRUCache,
|
|
402
|
+
MemoryCache,
|
|
403
|
+
MemoCache,
|
|
404
|
+
RenderCache,
|
|
405
|
+
createCache,
|
|
406
|
+
memoize
|
|
407
|
+
};
|
|
408
|
+
export {
|
|
409
|
+
LRUCache,
|
|
410
|
+
MemoCache,
|
|
411
|
+
MemoryCache,
|
|
412
|
+
RenderCache,
|
|
413
|
+
createCache,
|
|
414
|
+
cache_default as default,
|
|
415
|
+
memoize
|
|
416
|
+
};
|
|
417
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cache.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Coherent.js Advanced Caching\n * \n * Smart caching strategies for performance optimization\n * \n * @module performance/cache\n */\n\n/**\n * LRU Cache\n * Least Recently Used cache implementation\n */\nexport class LRUCache {\n constructor(options = {}) {\n this.maxSize = options.maxSize || 100;\n this.ttl = options.ttl || null; // Time to live in ms\n this.cache = new Map();\n this.accessOrder = [];\n }\n\n /**\n * Get value from cache\n */\n get(key) {\n if (!this.cache.has(key)) {\n return undefined;\n }\n\n const entry = this.cache.get(key);\n\n // Check TTL\n if (this.ttl && Date.now() - entry.timestamp > this.ttl) {\n this.delete(key);\n return undefined;\n }\n\n // Update access order\n this.updateAccessOrder(key);\n\n return entry.value;\n }\n\n /**\n * Set value in cache\n */\n set(key, value) {\n // Remove if exists\n if (this.cache.has(key)) {\n this.delete(key);\n }\n\n // Evict if at capacity\n if (this.cache.size >= this.maxSize) {\n this.evict();\n }\n\n // Add new entry\n this.cache.set(key, {\n value,\n timestamp: Date.now()\n });\n\n this.accessOrder.push(key);\n\n return this;\n }\n\n /**\n * Check if key exists\n */\n has(key) {\n if (!this.cache.has(key)) {\n return false;\n }\n\n const entry = this.cache.get(key);\n\n // Check TTL\n if (this.ttl && Date.now() - entry.timestamp > this.ttl) {\n this.delete(key);\n return false;\n }\n\n return true;\n }\n\n /**\n * Delete key\n */\n delete(key) {\n this.cache.delete(key);\n const index = this.accessOrder.indexOf(key);\n if (index > -1) {\n this.accessOrder.splice(index, 1);\n }\n return this;\n }\n\n /**\n * Clear cache\n */\n clear() {\n this.cache.clear();\n this.accessOrder = [];\n return this;\n }\n\n /**\n * Get cache size\n */\n size() {\n return this.cache.size;\n }\n\n /**\n * Update access order\n */\n updateAccessOrder(key) {\n const index = this.accessOrder.indexOf(key);\n if (index > -1) {\n this.accessOrder.splice(index, 1);\n }\n this.accessOrder.push(key);\n }\n\n /**\n * Evict least recently used\n */\n evict() {\n if (this.accessOrder.length > 0) {\n const oldest = this.accessOrder.shift();\n this.cache.delete(oldest);\n }\n }\n\n /**\n * Get all keys\n */\n keys() {\n return Array.from(this.cache.keys());\n }\n\n /**\n * Get all values\n */\n values() {\n return Array.from(this.cache.values()).map(entry => entry.value);\n }\n\n /**\n * Get statistics\n */\n getStats() {\n return {\n size: this.cache.size,\n maxSize: this.maxSize,\n utilizationPercent: (this.cache.size / this.maxSize * 100).toFixed(2),\n oldestKey: this.accessOrder[0],\n newestKey: this.accessOrder[this.accessOrder.length - 1]\n };\n }\n}\n\n/**\n * Memory Cache with strategies\n */\nexport class MemoryCache {\n constructor(options = {}) {\n this.options = {\n strategy: 'lru', // lru, lfu, fifo\n maxSize: 100,\n ttl: null,\n ...options\n };\n\n this.cache = new Map();\n this.metadata = new Map();\n this.hits = 0;\n this.misses = 0;\n }\n\n /**\n * Get from cache\n */\n get(key) {\n if (!this.cache.has(key)) {\n this.misses++;\n return undefined;\n }\n\n const entry = this.cache.get(key);\n\n // Check TTL\n if (entry.ttl && Date.now() > entry.expiresAt) {\n this.delete(key);\n this.misses++;\n return undefined;\n }\n\n // Update metadata\n this.updateMetadata(key);\n this.hits++;\n\n return entry.value;\n }\n\n /**\n * Set in cache\n */\n set(key, value, options = {}) {\n // Evict if needed\n if (this.cache.size >= this.options.maxSize && !this.cache.has(key)) {\n this.evict();\n }\n\n const ttl = options.ttl || this.options.ttl;\n\n this.cache.set(key, {\n value,\n ttl,\n expiresAt: ttl ? Date.now() + ttl : null,\n createdAt: Date.now()\n });\n\n this.metadata.set(key, {\n accessCount: 0,\n lastAccess: Date.now()\n });\n\n return this;\n }\n\n /**\n * Update metadata based on strategy\n */\n updateMetadata(key) {\n const meta = this.metadata.get(key);\n if (meta) {\n meta.accessCount++;\n meta.lastAccess = Date.now();\n }\n }\n\n /**\n * Evict based on strategy\n */\n evict() {\n let keyToEvict;\n\n switch (this.options.strategy) {\n case 'lru': // Least Recently Used\n keyToEvict = this.findLRU();\n break;\n case 'lfu': // Least Frequently Used\n keyToEvict = this.findLFU();\n break;\n case 'fifo': // First In First Out\n keyToEvict = this.findFIFO();\n break;\n default:\n keyToEvict = this.cache.keys().next().value;\n }\n\n if (keyToEvict) {\n this.delete(keyToEvict);\n }\n }\n\n /**\n * Find least recently used key\n */\n findLRU() {\n let oldest = null;\n let oldestTime = Infinity;\n\n for (const [key, meta] of this.metadata.entries()) {\n if (meta.lastAccess < oldestTime) {\n oldestTime = meta.lastAccess;\n oldest = key;\n }\n }\n\n return oldest;\n }\n\n /**\n * Find least frequently used key\n */\n findLFU() {\n let leastUsed = null;\n let minCount = Infinity;\n\n for (const [key, meta] of this.metadata.entries()) {\n if (meta.accessCount < minCount) {\n minCount = meta.accessCount;\n leastUsed = key;\n }\n }\n\n return leastUsed;\n }\n\n /**\n * Find first in (oldest)\n */\n findFIFO() {\n let oldest = null;\n let oldestTime = Infinity;\n\n for (const [key, entry] of this.cache.entries()) {\n if (entry.createdAt < oldestTime) {\n oldestTime = entry.createdAt;\n oldest = key;\n }\n }\n\n return oldest;\n }\n\n /**\n * Check if key exists\n */\n has(key) {\n return this.cache.has(key);\n }\n\n /**\n * Delete key\n */\n delete(key) {\n this.cache.delete(key);\n this.metadata.delete(key);\n return this;\n }\n\n /**\n * Clear cache\n */\n clear() {\n this.cache.clear();\n this.metadata.clear();\n this.hits = 0;\n this.misses = 0;\n return this;\n }\n\n /**\n * Get cache statistics\n */\n getStats() {\n const total = this.hits + this.misses;\n const hitRate = total > 0 ? (this.hits / total * 100).toFixed(2) : 0;\n\n return {\n size: this.cache.size,\n maxSize: this.options.maxSize,\n hits: this.hits,\n misses: this.misses,\n hitRate: `${hitRate}%`,\n strategy: this.options.strategy\n };\n }\n}\n\n/**\n * Memoization cache\n */\nexport class MemoCache {\n constructor(options = {}) {\n this.cache = new LRUCache(options);\n this.keyGenerator = options.keyGenerator || this.defaultKeyGenerator;\n }\n\n /**\n * Default key generator\n */\n defaultKeyGenerator(...args) {\n return JSON.stringify(args);\n }\n\n /**\n * Memoize a function\n */\n memoize(fn) {\n return (...args) => {\n const key = this.keyGenerator(...args);\n \n if (this.cache.has(key)) {\n return this.cache.get(key);\n }\n\n const result = fn(...args);\n this.cache.set(key, result);\n \n return result;\n };\n }\n\n /**\n * Clear memoization cache\n */\n clear() {\n this.cache.clear();\n }\n\n /**\n * Get statistics\n */\n getStats() {\n return this.cache.getStats();\n }\n}\n\n/**\n * Component render cache\n */\nexport class RenderCache {\n constructor(options = {}) {\n this.cache = new MemoryCache({\n maxSize: options.maxSize || 50,\n ttl: options.ttl || 60000, // 1 minute default\n strategy: 'lru'\n });\n }\n\n /**\n * Generate cache key for component\n */\n generateKey(component, props) {\n const componentName = component.name || 'anonymous';\n const propsKey = this.hashProps(props);\n return `${componentName}:${propsKey}`;\n }\n\n /**\n * Hash props for cache key\n */\n hashProps(props) {\n try {\n return JSON.stringify(props, Object.keys(props).sort());\n } catch {\n return String(Date.now());\n }\n }\n\n /**\n * Get cached render\n */\n get(component, props) {\n const key = this.generateKey(component, props);\n return this.cache.get(key);\n }\n\n /**\n * Cache render result\n */\n set(component, props, result, options = {}) {\n const key = this.generateKey(component, props);\n this.cache.set(key, result, options);\n }\n\n /**\n * Clear cache\n */\n clear() {\n this.cache.clear();\n }\n\n /**\n * Get statistics\n */\n getStats() {\n return this.cache.getStats();\n }\n}\n\n/**\n * Create a cache instance\n */\nexport function createCache(type = 'lru', options = {}) {\n switch (type) {\n case 'lru':\n return new LRUCache(options);\n case 'memory':\n return new MemoryCache(options);\n case 'memo':\n return new MemoCache(options);\n case 'render':\n return new RenderCache(options);\n default:\n return new LRUCache(options);\n }\n}\n\n/**\n * Memoize a function\n */\nexport function memoize(fn, options = {}) {\n const cache = new MemoCache(options);\n return cache.memoize(fn);\n}\n\nexport default {\n LRUCache,\n MemoryCache,\n MemoCache,\n RenderCache,\n createCache,\n memoize\n};\n"],
|
|
5
|
+
"mappings": ";AAYO,IAAM,WAAN,MAAe;AAAA,EACpB,YAAY,UAAU,CAAC,GAAG;AACxB,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,MAAM,QAAQ,OAAO;AAC1B,SAAK,QAAQ,oBAAI,IAAI;AACrB,SAAK,cAAc,CAAC;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,KAAK;AACP,QAAI,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;AACxB,aAAO;AAAA,IACT;AAEA,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAGhC,QAAI,KAAK,OAAO,KAAK,IAAI,IAAI,MAAM,YAAY,KAAK,KAAK;AACvD,WAAK,OAAO,GAAG;AACf,aAAO;AAAA,IACT;AAGA,SAAK,kBAAkB,GAAG;AAE1B,WAAO,MAAM;AAAA,EACf;AAAA;AAAA;AAAA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