limited-cache 2.0.0 → 2.1.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 (64) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/CODE_OF_CONDUCT.md +103 -47
  3. package/{CONTRIBUTING.md → CONTRIBUTING.template.md} +4 -2
  4. package/LICENSE +1 -1
  5. package/README.md +2 -2
  6. package/dist/core/LimitedCache.d.ts +4 -3
  7. package/dist/core/LimitedCache.d.ts.map +1 -0
  8. package/dist/core/LimitedCache.js +29 -0
  9. package/dist/core/LimitedCache.js.map +1 -0
  10. package/dist/core/LimitedCacheObject.d.ts +5 -4
  11. package/dist/core/LimitedCacheObject.d.ts.map +1 -0
  12. package/dist/core/LimitedCacheObject.js +52 -0
  13. package/dist/core/LimitedCacheObject.js.map +1 -0
  14. package/dist/core/builtIns.d.ts +12 -11
  15. package/dist/core/builtIns.d.ts.map +1 -0
  16. package/dist/core/builtIns.js +5 -0
  17. package/dist/core/builtIns.js.map +1 -0
  18. package/dist/core/defaultOptions.d.ts +6 -5
  19. package/dist/core/defaultOptions.d.ts.map +1 -0
  20. package/dist/core/defaultOptions.js +14 -0
  21. package/dist/core/defaultOptions.js.map +1 -0
  22. package/dist/core/limitedCacheUtil.d.ts +13 -12
  23. package/dist/core/limitedCacheUtil.d.ts.map +1 -0
  24. package/dist/core/limitedCacheUtil.js +14 -0
  25. package/dist/core/limitedCacheUtil.js.map +1 -0
  26. package/dist/core/lowLevelFunctions.d.ts +14 -13
  27. package/dist/core/lowLevelFunctions.d.ts.map +1 -0
  28. package/dist/core/lowLevelFunctions.js +240 -0
  29. package/dist/core/lowLevelFunctions.js.map +1 -0
  30. package/dist/index.cjs +388 -0
  31. package/dist/index.d.ts +7 -6
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +7 -8
  34. package/dist/index.js.map +1 -0
  35. package/dist/types.d.ts +58 -60
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +2 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +82 -74
  40. package/src/__tests__/LimitedCache.test.ts +5 -5
  41. package/src/__tests__/LimitedCacheObject.test.ts +6 -4
  42. package/src/__tests__/lowLevelFunctions.test.ts +17 -13
  43. package/src/__tests__/scenarios/keys.test.ts +1 -1
  44. package/src/__tests__/scenarios/maxCacheSize.test.ts +3 -3
  45. package/src/__tests__/scenarios/maxCacheTime.test.ts +2 -2
  46. package/src/__tests__/scenarios/values.test.ts +1 -1
  47. package/src/__tests__/typeChecks/LimitedCacheObjectTypes.test.ts +4 -2
  48. package/src/__tests__/typeChecks/LimitedCacheTypes.test.ts +4 -2
  49. package/src/__tests__/typeChecks/lowLevelFunctionsTypes.test.ts +4 -2
  50. package/src/core/lowLevelFunctions.ts +5 -5
  51. package/dist/limited-cache.cjs.development.js +0 -469
  52. package/dist/limited-cache.cjs.development.js.map +0 -1
  53. package/dist/limited-cache.cjs.production.min.js +0 -2
  54. package/dist/limited-cache.cjs.production.min.js.map +0 -1
  55. package/dist/limited-cache.esm.js +0 -448
  56. package/dist/limited-cache.esm.js.map +0 -1
  57. package/legacy-types/ts3.x/dist/core/LimitedCache.d.ts +0 -3
  58. package/legacy-types/ts3.x/dist/core/LimitedCacheObject.d.ts +0 -4
  59. package/legacy-types/ts3.x/dist/core/builtIns.d.ts +0 -11
  60. package/legacy-types/ts3.x/dist/core/defaultOptions.d.ts +0 -5
  61. package/legacy-types/ts3.x/dist/core/limitedCacheUtil.d.ts +0 -12
  62. package/legacy-types/ts3.x/dist/core/lowLevelFunctions.d.ts +0 -13
  63. package/legacy-types/ts3.x/dist/index.d.ts +0 -6
  64. package/legacy-types/ts3.x/dist/types.d.ts +0 -60
@@ -1,448 +0,0 @@
1
- var CURRENT_META_VERSION = 2;
2
- var MAXIMUM_CACHE_TIME = 365 * 86400 * 1000;
3
- var defaultOptions = {
4
- // Public
5
- maxCacheSize: 100,
6
- maxCacheTime: 86400 * 1000,
7
- // Development-only
8
- warnIfItemPurgedBeforeTime: 5000,
9
- // Private
10
- opLimit: 200,
11
- scanLimit: 50
12
- };
13
-
14
- function _extends() {
15
- _extends = Object.assign || function (target) {
16
- for (var i = 1; i < arguments.length; i++) {
17
- var source = arguments[i];
18
-
19
- for (var key in source) {
20
- if (Object.prototype.hasOwnProperty.call(source, key)) {
21
- target[key] = source[key];
22
- }
23
- }
24
- }
25
-
26
- return target;
27
- };
28
-
29
- return _extends.apply(this, arguments);
30
- }
31
-
32
- // To help minification
33
- var objectCreate = Object.create,
34
- objectAssign = Object.assign,
35
- hasOwnProperty = Object.prototype.hasOwnProperty;
36
- var dateNow = Date.now;
37
-
38
- /* Initialization and options */
39
-
40
- var positiveNumberOrZero = function positiveNumberOrZero(value) {
41
- return Math.max(value, 0) || 0;
42
- };
43
-
44
- var normalizeOptions = function normalizeOptions(cacheMetaOptions) {
45
- objectAssign(cacheMetaOptions, {
46
- maxCacheSize: positiveNumberOrZero(cacheMetaOptions.maxCacheSize),
47
- maxCacheTime: positiveNumberOrZero(cacheMetaOptions.maxCacheTime),
48
- opLimit: positiveNumberOrZero(cacheMetaOptions.opLimit)
49
- });
50
-
51
- if (process.env.NODE_ENV !== 'production') {
52
- cacheMetaOptions.warnIfItemPurgedBeforeTime = positiveNumberOrZero(cacheMetaOptions.warnIfItemPurgedBeforeTime);
53
- }
54
-
55
- return cacheMetaOptions;
56
- };
57
-
58
- var isCacheMeta = function isCacheMeta(cacheMeta) {
59
- return !!cacheMeta && !!cacheMeta.limitedCacheMetaVersion;
60
- };
61
-
62
- var upgradeCacheMeta = function upgradeCacheMeta(cacheMeta) {
63
- if (!isCacheMeta(cacheMeta)) {
64
- throw new Error('Limited-cache metadata is missing: please check your usage');
65
- }
66
-
67
- if (cacheMeta.limitedCacheMetaVersion !== CURRENT_META_VERSION) {
68
- // Version is out of date! (Today the only prior version is 1)
69
- // Version 1: Cache meta cannot be migrated because timestamps and keys are incompatible
70
- console.warn('Limited-cache metadata is from an incompatible version (1). It must be reset.');
71
- cacheMeta.limitedCacheMetaVersion = CURRENT_META_VERSION;
72
- lowLevelReset(cacheMeta);
73
- }
74
- };
75
-
76
- var lowLevelSetOptions = function lowLevelSetOptions(cacheMeta, options) {
77
- upgradeCacheMeta(cacheMeta);
78
- return normalizeOptions(objectAssign(cacheMeta.options, options));
79
- };
80
-
81
- var lowLevelInit = function lowLevelInit(optionsOrCacheMeta) {
82
- if (isCacheMeta(optionsOrCacheMeta)) {
83
- var existingCacheMeta = optionsOrCacheMeta;
84
- upgradeCacheMeta(existingCacheMeta);
85
- return existingCacheMeta;
86
- } // Else: it's options
87
-
88
-
89
- var fullOptions = normalizeOptions(_extends({}, defaultOptions, optionsOrCacheMeta)); // The cacheMeta is created once, and persists per instance
90
-
91
- var newCacheMeta = lowLevelReset({
92
- limitedCacheMetaVersion: CURRENT_META_VERSION,
93
- options: fullOptions
94
- });
95
- return newCacheMeta;
96
- };
97
- /* Internal cache manipulation */
98
-
99
-
100
- var _getExpireTime = function _getExpireTime(cacheMeta, cacheKey) {
101
- var maxCacheTime = cacheMeta.options.maxCacheTime,
102
- keyInfo = cacheMeta.keyInfo[cacheKey];
103
-
104
- if (!keyInfo) {
105
- // A missing record is always treated as expired
106
- return 0;
107
- } // If we have an exact expireTime then honor it. Otherwise it'll depend on the current maxCacheTime.
108
-
109
-
110
- var setTime = keyInfo[0],
111
- expireTime = keyInfo[1];
112
- return expireTime || setTime + (maxCacheTime || MAXIMUM_CACHE_TIME);
113
- };
114
-
115
- var _cacheKeyHasExpired = function _cacheKeyHasExpired(cacheMeta, cacheKey, now) {
116
- return _getExpireTime(cacheMeta, cacheKey) < now;
117
- };
118
-
119
- var lowLevelDoMaintenance = function lowLevelDoMaintenance(cacheMeta) {
120
- upgradeCacheMeta(cacheMeta);
121
- var cache = cacheMeta.cache,
122
- keyList = cacheMeta.keyList,
123
- keyInfo = cacheMeta.keyInfo;
124
- var now = dateNow(); // Rebuild cache from keyList only, checking timestamps to auto-remove expired
125
-
126
- var _keyList$reduce = keyList.reduce(function (acc, cacheKey) {
127
- var accCache = acc[0],
128
- accKeyList = acc[1],
129
- accKeyInfo = acc[2];
130
-
131
- if (!_cacheKeyHasExpired(cacheMeta, cacheKey, now)) {
132
- accCache[cacheKey] = cache[cacheKey];
133
- accKeyList.push(cacheKey);
134
- accKeyInfo[cacheKey] = keyInfo[cacheKey];
135
- }
136
-
137
- return acc;
138
- }, [{}, [], objectCreate(null)]),
139
- newCache = _keyList$reduce[0],
140
- newKeyList = _keyList$reduce[1],
141
- newKeyInfo = _keyList$reduce[2];
142
-
143
- return objectAssign(cacheMeta, {
144
- cache: newCache,
145
- keyList: newKeyList,
146
- keyInfo: newKeyInfo,
147
- opsLeft: cacheMeta.options.opLimit
148
- });
149
- };
150
-
151
- var _removeFromIndex = function _removeFromIndex(cacheMeta, startIndex, now) {
152
- var cache = cacheMeta.cache,
153
- keyList = cacheMeta.keyList,
154
- keyInfo = cacheMeta.keyInfo; // Always remove the item requested, and also remove any neighbors who have expired
155
-
156
- var nextIndex = startIndex;
157
- var nextCacheKey = keyList[startIndex];
158
- var keyListLength = keyList.length;
159
-
160
- do {
161
- // Remove the 'next' item
162
- cache[nextCacheKey] = keyInfo[nextCacheKey] = undefined; // Now advance and decide whether to keep going
163
-
164
- nextIndex++;
165
- nextCacheKey = keyList[nextIndex];
166
- } while (nextIndex < keyListLength && _cacheKeyHasExpired(cacheMeta, nextCacheKey, now)); // Remove the index for everything from the startIndex until we stopped
167
-
168
-
169
- keyList.splice(startIndex, nextIndex - startIndex);
170
- };
171
-
172
- var _removeItemsToMakeRoom = function _removeItemsToMakeRoom(cacheMeta, now) {
173
- var _cacheMeta$options = cacheMeta.options,
174
- scanLimit = _cacheMeta$options.scanLimit,
175
- warnIfItemPurgedBeforeTime = _cacheMeta$options.warnIfItemPurgedBeforeTime,
176
- cache = cacheMeta.cache,
177
- keyList = cacheMeta.keyList,
178
- keyInfo = cacheMeta.keyInfo; // These track the soonest-to-expire thing we've found. It may not actually be "oldest".
179
- // By default we'll remove the item at the head of the queue, unless we find something better.
180
-
181
- var oldestItemIndex = 0;
182
-
183
- var oldestExpireTime = _getExpireTime(cacheMeta, keyList[0]);
184
-
185
- if (oldestExpireTime > now) {
186
- // The head of the list hasn't yet expired: scan for a better candidate to remove
187
- var indexToCheck = 0;
188
- var maxIndexToCheck = Math.min(keyList.length, scanLimit);
189
-
190
- while (indexToCheck < maxIndexToCheck) {
191
- var cacheKeyForIndex = keyList[indexToCheck];
192
-
193
- var expireTimeForIndex = _getExpireTime(cacheMeta, cacheKeyForIndex); // We only consider it if it's eligible for expiration: otherwise it can't be a better option
194
- // than the default head-of-queue
195
-
196
-
197
- if (expireTimeForIndex < now) {
198
- // We found an expired item! This wins automatically
199
- oldestItemIndex = indexToCheck;
200
- oldestExpireTime = 0;
201
- break;
202
- }
203
-
204
- if (expireTimeForIndex < oldestExpireTime) {
205
- // We have a new leader
206
- oldestItemIndex = indexToCheck;
207
- oldestExpireTime = expireTimeForIndex;
208
- }
209
-
210
- indexToCheck += 1;
211
- }
212
- } // Warn if the 'oldest' item is more recent than we'd like: this means it cycled into and out of
213
- // cache too quickly for the cache to be useful.
214
-
215
-
216
- if (process.env.NODE_ENV !== 'production' && warnIfItemPurgedBeforeTime && oldestExpireTime > now) {
217
- var oldestItemKey = keyList[oldestItemIndex];
218
- var _keyInfo$oldestItemKe = keyInfo[oldestItemKey],
219
- oldestItemSetTime = _keyInfo$oldestItemKe[0],
220
- oldestItemExpireTime = _keyInfo$oldestItemKe[1];
221
-
222
- if (now - oldestItemSetTime < warnIfItemPurgedBeforeTime) {
223
- console.warn('Purged an item from cache while it was still fresh: you may want to increase maxCacheSize', {
224
- currentTime: now,
225
- key: oldestItemKey,
226
- item: cache[oldestItemKey],
227
- setTime: oldestItemSetTime,
228
- expireTime: oldestItemExpireTime,
229
- timeInCache: now - oldestItemSetTime
230
- });
231
- }
232
- } // Remove the oldest item we found, plus any expired neighbors
233
-
234
-
235
- _removeFromIndex(cacheMeta, oldestItemIndex, now);
236
- };
237
- /* Accessors */
238
-
239
-
240
- var lowLevelHas = function lowLevelHas(cacheMeta, cacheKey) {
241
- upgradeCacheMeta(cacheMeta);
242
- var cache = cacheMeta.cache;
243
-
244
- if (hasOwnProperty.call(cache, cacheKey) && cache[cacheKey] !== undefined) {
245
- if (!_cacheKeyHasExpired(cacheMeta, cacheKey, dateNow())) {
246
- return true;
247
- } // If it's expired, clear the value so that we can short-circuit future lookups
248
-
249
-
250
- cache[cacheKey] = undefined;
251
- }
252
-
253
- return false;
254
- };
255
-
256
- var lowLevelGetOne = function lowLevelGetOne(cacheMeta, cacheKey) {
257
- upgradeCacheMeta(cacheMeta);
258
-
259
- if (lowLevelHas(cacheMeta, cacheKey)) {
260
- return cacheMeta.cache[cacheKey];
261
- }
262
-
263
- return;
264
- };
265
-
266
- var lowLevelGetAll = function lowLevelGetAll(cacheMeta) {
267
- upgradeCacheMeta(cacheMeta); // Remove all expired values, and return whatever's left
268
-
269
- lowLevelDoMaintenance(cacheMeta); // Retype because there won't be any `undefined` values after doMaintenance
270
-
271
- return cacheMeta.cache;
272
- };
273
-
274
- var lowLevelSet = function lowLevelSet(cacheMeta, cacheKey, item) {
275
- upgradeCacheMeta(cacheMeta);
276
- var maxCacheSize = cacheMeta.options.maxCacheSize,
277
- keyList = cacheMeta.keyList,
278
- keyInfo = cacheMeta.keyInfo;
279
- var now = dateNow();
280
- var isNew = !keyInfo[cacheKey];
281
-
282
- if (cacheMeta.cache[cacheKey] !== item) {
283
- var _extends2;
284
-
285
- // The cache itself is immutable (but the rest of cacheMeta is not)
286
- cacheMeta.cache = _extends({}, cacheMeta.cache, (_extends2 = {}, _extends2[cacheKey] = item, _extends2));
287
- } // We've now set or updated it. Regardless of whether it's new, bump its set time
288
- // @TODO: expireTime override
289
-
290
-
291
- keyInfo[cacheKey] = [now, 0];
292
-
293
- if (isNew) {
294
- // It's a new key: grow the cache, then shrink it if we can
295
- keyList.push(cacheKey);
296
- cacheMeta.opsLeft--;
297
-
298
- if (cacheMeta.opsLeft <= 0) {
299
- // Time for an oil change
300
- lowLevelDoMaintenance(cacheMeta);
301
- }
302
-
303
- if (maxCacheSize && cacheMeta.keyList.length > maxCacheSize) {
304
- // We're still over the limit: drop at least one item
305
- _removeItemsToMakeRoom(cacheMeta, now);
306
- }
307
- }
308
-
309
- if (_cacheKeyHasExpired(cacheMeta, keyList[0], now)) {
310
- // While we're here, if we need to expire the head of the queue then drop it
311
- _removeFromIndex(cacheMeta, 0, now);
312
- }
313
-
314
- return cacheMeta;
315
- };
316
-
317
- var lowLevelRemove = function lowLevelRemove(cacheMeta, cacheKey) {
318
- upgradeCacheMeta(cacheMeta);
319
- var cache = cacheMeta.cache,
320
- keyInfo = cacheMeta.keyInfo;
321
-
322
- if (keyInfo[cacheKey]) {
323
- if (cache[cacheKey] !== undefined) {
324
- var _extends3;
325
-
326
- cacheMeta.cache = _extends({}, cache, (_extends3 = {}, _extends3[cacheKey] = undefined, _extends3));
327
- }
328
-
329
- keyInfo[cacheKey] = undefined;
330
- }
331
-
332
- return cacheMeta;
333
- };
334
-
335
- var lowLevelReset = function lowLevelReset(cacheMeta) {
336
- upgradeCacheMeta(cacheMeta);
337
- return objectAssign(cacheMeta, {
338
- cache: {},
339
- keyList: [],
340
- keyInfo: objectCreate(null),
341
- opsLeft: cacheMeta.options.opLimit
342
- });
343
- };
344
-
345
- // Doing this via a helper function makes the typeChecks easier, and minifies better.
346
-
347
- var bindFunctionToCacheMeta = function bindFunctionToCacheMeta( // eslint-disable-next-line @typescript-eslint/no-explicit-any
348
- fn, cacheMeta) {
349
- return fn.bind(null, cacheMeta);
350
- };
351
-
352
- var LimitedCache = function LimitedCache(options) {
353
- var cacheMeta = lowLevelInit(options);
354
- return {
355
- get: bindFunctionToCacheMeta(lowLevelGetOne, cacheMeta),
356
- getAll: bindFunctionToCacheMeta(lowLevelGetAll, cacheMeta),
357
- has: bindFunctionToCacheMeta(lowLevelHas, cacheMeta),
358
- set: function set(cacheKey, item) {
359
- lowLevelSet(cacheMeta, cacheKey, item);
360
- return item;
361
- },
362
- remove: function remove(cacheKey) {
363
- lowLevelRemove(cacheMeta, cacheKey);
364
- return true;
365
- },
366
- reset: bindFunctionToCacheMeta(lowLevelReset, cacheMeta),
367
- getCacheMeta: function getCacheMeta() {
368
- return cacheMeta;
369
- },
370
- getOptions: function getOptions() {
371
- return cacheMeta.options;
372
- },
373
- setOptions: bindFunctionToCacheMeta(lowLevelSetOptions, cacheMeta),
374
- doMaintenance: bindFunctionToCacheMeta(lowLevelDoMaintenance, cacheMeta)
375
- };
376
- };
377
-
378
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
379
-
380
- var proxyHandler = {
381
- get: function get(cacheMeta, cacheKey) {
382
- if (cacheKey === 'hasOwnProperty') {
383
- return hasOwnProperty;
384
- }
385
-
386
- return lowLevelGetOne(cacheMeta, cacheKey);
387
- },
388
- getOwnPropertyDescriptor: function getOwnPropertyDescriptor(cacheMeta, cacheKey) {
389
- var hasResult = lowLevelHas(cacheMeta, cacheKey);
390
- var getResult = lowLevelGetOne(cacheMeta, cacheKey);
391
-
392
- if (hasResult) {
393
- return {
394
- configurable: true,
395
- enumerable: hasResult,
396
- value: getResult,
397
- writable: true
398
- };
399
- }
400
-
401
- return;
402
- },
403
- has: lowLevelHas,
404
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
405
- set: function set(cacheMeta, cacheKey, item) {
406
- lowLevelSet(cacheMeta, cacheKey, item);
407
- return item;
408
- },
409
- deleteProperty: function deleteProperty(cacheMeta, cacheKey) {
410
- lowLevelRemove(cacheMeta, cacheKey);
411
- return true;
412
- },
413
- ownKeys: function ownKeys(cacheMeta) {
414
- return Object.keys(lowLevelGetAll(cacheMeta));
415
- }
416
- };
417
- /**
418
- * So that we can retrieve the cacheMeta for a LimitedCacheObject, without polluting its properties, each proxy
419
- * is associated back to its internal cacheMeta here.
420
- */
421
-
422
- var cacheMetasForProxies = /*#__PURE__*/new WeakMap();
423
-
424
- var LimitedCacheObject = function LimitedCacheObject(options) {
425
- var cacheMeta = lowLevelInit(options);
426
- var limitedCacheObject = new Proxy(cacheMeta, proxyHandler);
427
- cacheMetasForProxies.set(limitedCacheObject, cacheMeta);
428
- return limitedCacheObject;
429
- };
430
-
431
- var getCacheMetaFromObject = function getCacheMetaFromObject(instance) {
432
- return cacheMetasForProxies.get(instance);
433
- };
434
-
435
- var limitedCacheUtil = {
436
- init: lowLevelInit,
437
- get: lowLevelGetOne,
438
- getAll: lowLevelGetAll,
439
- has: lowLevelHas,
440
- set: lowLevelSet,
441
- remove: lowLevelRemove,
442
- reset: lowLevelReset,
443
- doMaintenance: lowLevelDoMaintenance,
444
- setOptions: lowLevelSetOptions
445
- };
446
-
447
- export { CURRENT_META_VERSION, LimitedCache, LimitedCacheObject, MAXIMUM_CACHE_TIME, defaultOptions, getCacheMetaFromObject, isCacheMeta, limitedCacheUtil, lowLevelDoMaintenance, lowLevelGetAll, lowLevelGetOne, lowLevelHas, lowLevelInit, lowLevelRemove, lowLevelReset, lowLevelSet, lowLevelSetOptions, upgradeCacheMeta };
448
- //# sourceMappingURL=limited-cache.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"limited-cache.esm.js","sources":["../src/core/defaultOptions.ts","../src/core/builtIns.ts","../src/core/lowLevelFunctions.ts","../src/core/LimitedCache.ts","../src/core/LimitedCacheObject.ts","../src/core/limitedCacheUtil.ts"],"sourcesContent":["import { LimitedCacheOptionsReadonly } from '../types';\n\nconst CURRENT_META_VERSION = 2;\nconst MAXIMUM_CACHE_TIME = 365 * 86400 * 1000;\n\nconst defaultOptions: LimitedCacheOptionsReadonly = {\n // Public\n maxCacheSize: 100,\n maxCacheTime: 86400 * 1000,\n // Development-only\n warnIfItemPurgedBeforeTime: 5000,\n // Private\n opLimit: 200,\n scanLimit: 50,\n};\n\nexport { CURRENT_META_VERSION, MAXIMUM_CACHE_TIME, defaultOptions };\n","// To help minification\nconst {\n create: objectCreate,\n assign: objectAssign,\n prototype: { hasOwnProperty },\n} = Object;\nconst dateNow = Date.now;\n\nexport { objectAssign, objectCreate, dateNow, hasOwnProperty };\n","import { objectAssign, objectCreate, dateNow, hasOwnProperty } from './builtIns';\nimport { CURRENT_META_VERSION, MAXIMUM_CACHE_TIME, defaultOptions } from './defaultOptions';\nimport {\n LimitedCacheOptions,\n LimitedCacheOptionsReadonly,\n LimitedCacheMeta,\n LimitedCacheOptionsFull,\n DefaultItemType,\n} from '../types';\n\n/* Initialization and options */\n\nconst positiveNumberOrZero = (value: number): number => Math.max(value, 0) || 0;\n\nconst normalizeOptions = (cacheMetaOptions: LimitedCacheOptionsFull): LimitedCacheOptionsFull => {\n objectAssign(cacheMetaOptions, {\n maxCacheSize: positiveNumberOrZero(cacheMetaOptions.maxCacheSize),\n maxCacheTime: positiveNumberOrZero(cacheMetaOptions.maxCacheTime),\n opLimit: positiveNumberOrZero(cacheMetaOptions.opLimit),\n });\n\n if (process.env.NODE_ENV !== 'production') {\n cacheMetaOptions.warnIfItemPurgedBeforeTime = positiveNumberOrZero(\n cacheMetaOptions.warnIfItemPurgedBeforeTime,\n );\n }\n return cacheMetaOptions;\n};\n\nconst isCacheMeta = (cacheMeta: LimitedCacheMeta): boolean => {\n return !!cacheMeta && !!cacheMeta.limitedCacheMetaVersion;\n};\n\nconst upgradeCacheMeta = (cacheMeta: LimitedCacheMeta): void => {\n if (!isCacheMeta(cacheMeta)) {\n throw new Error('Limited-cache metadata is missing: please check your usage');\n }\n if (cacheMeta.limitedCacheMetaVersion !== CURRENT_META_VERSION) {\n // Version is out of date! (Today the only prior version is 1)\n // Version 1: Cache meta cannot be migrated because timestamps and keys are incompatible\n console.warn('Limited-cache metadata is from an incompatible version (1). It must be reset.');\n cacheMeta.limitedCacheMetaVersion = CURRENT_META_VERSION;\n lowLevelReset(cacheMeta);\n }\n};\n\nconst lowLevelSetOptions = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n options: LimitedCacheOptions,\n): LimitedCacheOptionsReadonly => {\n upgradeCacheMeta(cacheMeta);\n return normalizeOptions(objectAssign(cacheMeta.options, options));\n};\n\nconst lowLevelInit = <ItemType = DefaultItemType>(\n optionsOrCacheMeta?: LimitedCacheOptions | LimitedCacheMeta<ItemType>,\n): LimitedCacheMeta<ItemType> => {\n if (isCacheMeta(optionsOrCacheMeta as LimitedCacheMeta<ItemType>)) {\n const existingCacheMeta = optionsOrCacheMeta as LimitedCacheMeta<ItemType>;\n upgradeCacheMeta(existingCacheMeta);\n return existingCacheMeta;\n }\n // Else: it's options\n const fullOptions = normalizeOptions({ ...defaultOptions, ...optionsOrCacheMeta });\n\n // The cacheMeta is created once, and persists per instance\n const newCacheMeta = lowLevelReset({\n limitedCacheMetaVersion: CURRENT_META_VERSION,\n options: fullOptions,\n } as LimitedCacheMeta<ItemType>);\n\n return newCacheMeta;\n};\n\n/* Internal cache manipulation */\n\nconst _getExpireTime = (cacheMeta: LimitedCacheMeta, cacheKey: string): number => {\n const {\n options: { maxCacheTime },\n keyInfo: { [cacheKey]: keyInfo },\n } = cacheMeta;\n if (!keyInfo) {\n // A missing record is always treated as expired\n return 0;\n }\n // If we have an exact expireTime then honor it. Otherwise it'll depend on the current maxCacheTime.\n const [setTime, expireTime] = keyInfo;\n return expireTime || setTime + (maxCacheTime || MAXIMUM_CACHE_TIME);\n};\n\nconst _cacheKeyHasExpired = (\n cacheMeta: LimitedCacheMeta,\n cacheKey: string,\n now: number,\n): boolean => {\n return _getExpireTime(cacheMeta, cacheKey) < now;\n};\n\nconst lowLevelDoMaintenance = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n): LimitedCacheMeta<ItemType> => {\n upgradeCacheMeta(cacheMeta);\n const { cache, keyList, keyInfo } = cacheMeta;\n const now = dateNow();\n\n // Rebuild cache from keyList only, checking timestamps to auto-remove expired\n const [newCache, newKeyList, newKeyInfo] = keyList.reduce(\n (acc, cacheKey) => {\n const [accCache, accKeyList, accKeyInfo] = acc;\n if (!_cacheKeyHasExpired(cacheMeta, cacheKey, now)) {\n accCache[cacheKey] = cache[cacheKey];\n accKeyList.push(cacheKey);\n accKeyInfo[cacheKey] = keyInfo[cacheKey];\n }\n return acc;\n },\n [\n {} as typeof cacheMeta['cache'],\n [] as typeof cacheMeta['keyList'],\n objectCreate(null) as typeof cacheMeta['keyInfo'],\n ],\n );\n\n return objectAssign(cacheMeta, {\n cache: newCache,\n keyList: newKeyList,\n keyInfo: newKeyInfo,\n opsLeft: cacheMeta.options.opLimit,\n });\n};\n\nconst _removeFromIndex = (cacheMeta: LimitedCacheMeta, startIndex: number, now: number): void => {\n const { cache, keyList, keyInfo } = cacheMeta;\n\n // Always remove the item requested, and also remove any neighbors who have expired\n let nextIndex = startIndex;\n let nextCacheKey = keyList[startIndex];\n const keyListLength = keyList.length;\n do {\n // Remove the 'next' item\n\n cache[nextCacheKey] = keyInfo[nextCacheKey] = undefined;\n\n // Now advance and decide whether to keep going\n nextIndex++;\n nextCacheKey = keyList[nextIndex];\n } while (nextIndex < keyListLength && _cacheKeyHasExpired(cacheMeta, nextCacheKey, now));\n\n // Remove the index for everything from the startIndex until we stopped\n keyList.splice(startIndex, nextIndex - startIndex);\n};\n\nconst _removeItemsToMakeRoom = (cacheMeta: LimitedCacheMeta, now: number): void => {\n const {\n options: { scanLimit, warnIfItemPurgedBeforeTime },\n cache,\n keyList,\n keyInfo,\n } = cacheMeta;\n\n // These track the soonest-to-expire thing we've found. It may not actually be \"oldest\".\n // By default we'll remove the item at the head of the queue, unless we find something better.\n let oldestItemIndex = 0;\n let oldestExpireTime = _getExpireTime(cacheMeta, keyList[0]);\n\n if (oldestExpireTime > now) {\n // The head of the list hasn't yet expired: scan for a better candidate to remove\n let indexToCheck = 0;\n const maxIndexToCheck = Math.min(keyList.length, scanLimit);\n while (indexToCheck < maxIndexToCheck) {\n const cacheKeyForIndex = keyList[indexToCheck];\n let expireTimeForIndex = _getExpireTime(cacheMeta, cacheKeyForIndex);\n\n // We only consider it if it's eligible for expiration: otherwise it can't be a better option\n // than the default head-of-queue\n if (expireTimeForIndex < now) {\n // We found an expired item! This wins automatically\n oldestItemIndex = indexToCheck;\n oldestExpireTime = 0;\n break;\n }\n if (expireTimeForIndex < oldestExpireTime) {\n // We have a new leader\n oldestItemIndex = indexToCheck;\n oldestExpireTime = expireTimeForIndex;\n }\n indexToCheck += 1;\n }\n }\n\n // Warn if the 'oldest' item is more recent than we'd like: this means it cycled into and out of\n // cache too quickly for the cache to be useful.\n if (\n process.env.NODE_ENV !== 'production' &&\n warnIfItemPurgedBeforeTime &&\n oldestExpireTime > now\n ) {\n const oldestItemKey = keyList[oldestItemIndex];\n const [oldestItemSetTime, oldestItemExpireTime] = keyInfo[oldestItemKey]!;\n\n if (now - oldestItemSetTime < warnIfItemPurgedBeforeTime) {\n console.warn(\n 'Purged an item from cache while it was still fresh: you may want to increase maxCacheSize',\n {\n currentTime: now,\n key: oldestItemKey,\n item: cache[oldestItemKey],\n setTime: oldestItemSetTime,\n expireTime: oldestItemExpireTime,\n timeInCache: now - oldestItemSetTime,\n },\n );\n }\n }\n\n // Remove the oldest item we found, plus any expired neighbors\n _removeFromIndex(cacheMeta, oldestItemIndex, now);\n};\n\n/* Accessors */\n\nconst lowLevelHas = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n cacheKey: string,\n): boolean => {\n upgradeCacheMeta(cacheMeta);\n const { cache } = cacheMeta;\n if (hasOwnProperty.call(cache, cacheKey) && cache[cacheKey] !== undefined) {\n if (!_cacheKeyHasExpired(cacheMeta, cacheKey, dateNow())) {\n return true;\n }\n // If it's expired, clear the value so that we can short-circuit future lookups\n cache[cacheKey] = undefined;\n }\n return false;\n};\n\nconst lowLevelGetOne = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n cacheKey: string,\n): ItemType | undefined => {\n upgradeCacheMeta(cacheMeta);\n if (lowLevelHas(cacheMeta, cacheKey)) {\n return cacheMeta.cache[cacheKey];\n }\n return;\n};\n\nconst lowLevelGetAll = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n): Record<string, ItemType> => {\n upgradeCacheMeta(cacheMeta);\n // Remove all expired values, and return whatever's left\n lowLevelDoMaintenance(cacheMeta);\n // Retype because there won't be any `undefined` values after doMaintenance\n return cacheMeta.cache as Record<string, ItemType>;\n};\n\nconst lowLevelSet = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n cacheKey: string,\n item: ItemType,\n): LimitedCacheMeta<ItemType> => {\n upgradeCacheMeta(cacheMeta);\n\n const {\n options: { maxCacheSize },\n keyList,\n keyInfo,\n } = cacheMeta;\n\n const now = dateNow();\n const isNew = !keyInfo[cacheKey];\n\n if (cacheMeta.cache[cacheKey] !== item) {\n // The cache itself is immutable (but the rest of cacheMeta is not)\n cacheMeta.cache = {\n ...cacheMeta.cache,\n [cacheKey]: item,\n };\n }\n // We've now set or updated it. Regardless of whether it's new, bump its set time\n // @TODO: expireTime override\n keyInfo[cacheKey] = [now, 0];\n\n if (isNew) {\n // It's a new key: grow the cache, then shrink it if we can\n keyList.push(cacheKey);\n\n cacheMeta.opsLeft--;\n if (cacheMeta.opsLeft <= 0) {\n // Time for an oil change\n lowLevelDoMaintenance(cacheMeta);\n }\n\n if (maxCacheSize && cacheMeta.keyList.length > maxCacheSize) {\n // We're still over the limit: drop at least one item\n _removeItemsToMakeRoom(cacheMeta, now);\n }\n }\n\n if (_cacheKeyHasExpired(cacheMeta, keyList[0], now)) {\n // While we're here, if we need to expire the head of the queue then drop it\n _removeFromIndex(cacheMeta, 0, now);\n }\n\n return cacheMeta;\n};\n\nconst lowLevelRemove = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n cacheKey: string,\n): LimitedCacheMeta<ItemType> => {\n upgradeCacheMeta(cacheMeta);\n const { cache, keyInfo } = cacheMeta;\n\n if (keyInfo[cacheKey]) {\n if (cache[cacheKey] !== undefined) {\n cacheMeta.cache = {\n ...cache,\n [cacheKey]: undefined,\n };\n }\n keyInfo[cacheKey] = undefined;\n }\n\n return cacheMeta;\n};\n\nconst lowLevelReset = <ItemType = DefaultItemType>(\n cacheMeta: LimitedCacheMeta<ItemType>,\n): LimitedCacheMeta<ItemType> => {\n upgradeCacheMeta(cacheMeta);\n return objectAssign(cacheMeta, {\n cache: {},\n keyList: [],\n keyInfo: objectCreate(null),\n opsLeft: cacheMeta.options.opLimit,\n });\n};\n\nexport {\n isCacheMeta,\n upgradeCacheMeta,\n lowLevelInit,\n lowLevelGetOne,\n lowLevelGetAll,\n lowLevelHas,\n lowLevelSet,\n lowLevelRemove,\n lowLevelReset,\n lowLevelDoMaintenance,\n lowLevelSetOptions,\n};\n","import {\n lowLevelInit,\n lowLevelGetOne,\n lowLevelGetAll,\n lowLevelHas,\n lowLevelSet,\n lowLevelRemove,\n lowLevelReset,\n lowLevelSetOptions,\n lowLevelDoMaintenance,\n} from './lowLevelFunctions';\nimport {\n LimitedCacheOptions,\n LimitedCacheOptionsReadonly,\n LimitedCacheInstance,\n LimitedCacheMeta,\n DefaultItemType,\n} from '../types';\n\n// Most public functions just call a low-level function directly, passing the cacheMeta.\n// Doing this via a helper function makes the typeChecks easier, and minifies better.\nconst bindFunctionToCacheMeta = <ItemType>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fn: (cacheMeta: LimitedCacheMeta<ItemType>, ...otherArgs: any) => any,\n cacheMeta: LimitedCacheMeta<ItemType>,\n) => fn.bind(null, cacheMeta);\n\nconst LimitedCache = <ItemType = DefaultItemType>(\n options?: LimitedCacheOptions,\n): LimitedCacheInstance<ItemType> => {\n const cacheMeta = lowLevelInit<ItemType>(options);\n\n return {\n get: bindFunctionToCacheMeta<ItemType>(lowLevelGetOne, cacheMeta),\n getAll: bindFunctionToCacheMeta<ItemType>(lowLevelGetAll, cacheMeta),\n has: bindFunctionToCacheMeta<ItemType>(lowLevelHas, cacheMeta),\n set: (cacheKey, item): ItemType => {\n lowLevelSet(cacheMeta, cacheKey, item);\n return item;\n },\n remove: (cacheKey): true => {\n lowLevelRemove(cacheMeta, cacheKey);\n return true;\n },\n reset: bindFunctionToCacheMeta<ItemType>(lowLevelReset, cacheMeta),\n getCacheMeta: (): LimitedCacheMeta<ItemType> => cacheMeta,\n getOptions: (): LimitedCacheOptionsReadonly => cacheMeta.options,\n setOptions: bindFunctionToCacheMeta<ItemType>(lowLevelSetOptions, cacheMeta),\n doMaintenance: bindFunctionToCacheMeta<ItemType>(lowLevelDoMaintenance, cacheMeta),\n };\n};\n\nexport { LimitedCache };\n","import { hasOwnProperty } from './builtIns';\nimport {\n lowLevelInit,\n lowLevelGetOne,\n lowLevelGetAll,\n lowLevelHas,\n lowLevelSet,\n lowLevelRemove,\n} from './lowLevelFunctions';\nimport {\n LimitedCacheOptions,\n LimitedCacheObjectInstance,\n LimitedCacheMeta,\n DefaultItemType,\n} from '../types';\n\n// The `any` here doesn't escape out anywhere: it's overridden by the constructor below\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst proxyHandler: ProxyHandler<LimitedCacheObjectInstance<any>> = {\n get: (cacheMeta: LimitedCacheMeta, cacheKey: string) => {\n if (cacheKey === 'hasOwnProperty') {\n return hasOwnProperty;\n }\n return lowLevelGetOne(cacheMeta, cacheKey);\n },\n getOwnPropertyDescriptor: (cacheMeta: LimitedCacheMeta, cacheKey: string) => {\n const hasResult = lowLevelHas(cacheMeta, cacheKey);\n const getResult = lowLevelGetOne(cacheMeta, cacheKey);\n\n if (hasResult) {\n return {\n configurable: true,\n enumerable: hasResult,\n value: getResult,\n writable: true,\n };\n }\n return;\n },\n has: lowLevelHas,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n set: (cacheMeta: LimitedCacheMeta, cacheKey: string, item: any): any => {\n lowLevelSet(cacheMeta, cacheKey, item);\n return item;\n },\n deleteProperty: (cacheMeta: LimitedCacheMeta, cacheKey: string): true => {\n lowLevelRemove(cacheMeta, cacheKey);\n return true;\n },\n ownKeys: (cacheMeta: LimitedCacheMeta) => Object.keys(lowLevelGetAll(cacheMeta)),\n};\n\n/**\n * So that we can retrieve the cacheMeta for a LimitedCacheObject, without polluting its properties, each proxy\n * is associated back to its internal cacheMeta here.\n */\nconst cacheMetasForProxies = new WeakMap();\n\nconst LimitedCacheObject = <ItemType = DefaultItemType>(\n options?: LimitedCacheOptions,\n): LimitedCacheObjectInstance<ItemType> => {\n const cacheMeta = lowLevelInit(options);\n const limitedCacheObject = new Proxy(cacheMeta, proxyHandler);\n\n cacheMetasForProxies.set(limitedCacheObject, cacheMeta);\n return limitedCacheObject;\n};\n\nconst getCacheMetaFromObject = (instance: LimitedCacheObjectInstance): LimitedCacheMeta => {\n return cacheMetasForProxies.get(instance);\n};\n\nexport { LimitedCacheObject, getCacheMetaFromObject };\n","import {\n lowLevelGetOne,\n lowLevelGetAll,\n lowLevelHas,\n lowLevelInit,\n lowLevelDoMaintenance,\n lowLevelRemove,\n lowLevelReset,\n lowLevelSet,\n lowLevelSetOptions,\n} from './lowLevelFunctions';\n\nconst limitedCacheUtil = {\n init: lowLevelInit,\n get: lowLevelGetOne,\n getAll: lowLevelGetAll,\n has: lowLevelHas,\n set: lowLevelSet,\n remove: lowLevelRemove,\n reset: lowLevelReset,\n doMaintenance: lowLevelDoMaintenance,\n setOptions: lowLevelSetOptions,\n};\n\nexport { limitedCacheUtil };\n"],"names":["CURRENT_META_VERSION","MAXIMUM_CACHE_TIME","defaultOptions","maxCacheSize","maxCacheTime","warnIfItemPurgedBeforeTime","opLimit","scanLimit","objectCreate","Object","create","objectAssign","assign","hasOwnProperty","prototype","dateNow","Date","now","positiveNumberOrZero","value","Math","max","normalizeOptions","cacheMetaOptions","process","env","NODE_ENV","isCacheMeta","cacheMeta","limitedCacheMetaVersion","upgradeCacheMeta","Error","console","warn","lowLevelReset","lowLevelSetOptions","options","lowLevelInit","optionsOrCacheMeta","existingCacheMeta","fullOptions","newCacheMeta","_getExpireTime","cacheKey","keyInfo","setTime","expireTime","_cacheKeyHasExpired","lowLevelDoMaintenance","cache","keyList","reduce","acc","accCache","accKeyList","accKeyInfo","push","newCache","newKeyList","newKeyInfo","opsLeft","_removeFromIndex","startIndex","nextIndex","nextCacheKey","keyListLength","length","undefined","splice","_removeItemsToMakeRoom","oldestItemIndex","oldestExpireTime","indexToCheck","maxIndexToCheck","min","cacheKeyForIndex","expireTimeForIndex","oldestItemKey","oldestItemSetTime","oldestItemExpireTime","currentTime","key","item","timeInCache","lowLevelHas","call","lowLevelGetOne","lowLevelGetAll","lowLevelSet","isNew","lowLevelRemove","bindFunctionToCacheMeta","fn","bind","LimitedCache","get","getAll","has","set","remove","reset","getCacheMeta","getOptions","setOptions","doMaintenance","proxyHandler","getOwnPropertyDescriptor","hasResult","getResult","configurable","enumerable","writable","deleteProperty","ownKeys","keys","cacheMetasForProxies","WeakMap","LimitedCacheObject","limitedCacheObject","Proxy","getCacheMetaFromObject","instance","limitedCacheUtil","init"],"mappings":"IAEMA,oBAAoB,GAAG;IACvBC,kBAAkB,GAAG,MAAM,KAAN,GAAc;IAEnCC,cAAc,GAAgC;AAClD;AACAC,EAAAA,YAAY,EAAE,GAFoC;AAGlDC,EAAAA,YAAY,EAAE,QAAQ,IAH4B;AAIlD;AACAC,EAAAA,0BAA0B,EAAE,IALsB;AAMlD;AACAC,EAAAA,OAAO,EAAE,GAPyC;AAQlDC,EAAAA,SAAS,EAAE;AARuC;;;;;;;;;;;;;;;;;;;;ACLpD;AACA,IACUC,YADV,GAIIC,MAJJ,CACEC,MADF;AAAA,IAEUC,YAFV,GAIIF,MAJJ,CAEEG,MAFF;AAAA,IAGeC,cAHf,GAIIJ,MAJJ,CAGEK,SAHF,CAGeD,cAHf;AAKA,IAAME,OAAO,GAAGC,IAAI,CAACC,GAArB;;ACIA;;AAEA,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD;AAAA,SAA2BC,IAAI,CAACC,GAAL,CAASF,KAAT,EAAgB,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 +0,0 @@
1
- import { LimitedCacheInstance } from '../types';
2
- declare const LimitedCache: <ItemType = any>(options?: Partial<import("../types").LimitedCacheOptionsFull> | null | undefined) => LimitedCacheInstance<ItemType>;
3
- export { LimitedCache };
@@ -1,4 +0,0 @@
1
- import { LimitedCacheObjectInstance, LimitedCacheMeta } from '../types';
2
- declare const LimitedCacheObject: <ItemType = any>(options?: Partial<import("../types").LimitedCacheOptionsFull> | null | undefined) => LimitedCacheObjectInstance<ItemType>;
3
- declare const getCacheMetaFromObject: (instance: LimitedCacheObjectInstance) => LimitedCacheMeta;
4
- export { LimitedCacheObject, getCacheMetaFromObject };
@@ -1,11 +0,0 @@
1
- declare const objectCreate: {
2
- (o: object | null): any;
3
- (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
4
- }, objectAssign: {
5
- <T, U>(target: T, source: U): T & U;
6
- <T_1, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
7
- <T_2, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
8
- (target: object, ...sources: any[]): any;
9
- }, hasOwnProperty: (v: string | number | symbol) => boolean;
10
- declare const dateNow: () => number;
11
- export { objectAssign, objectCreate, dateNow, hasOwnProperty };
@@ -1,5 +0,0 @@
1
- import { LimitedCacheOptionsReadonly } from '../types';
2
- declare const CURRENT_META_VERSION = 2;
3
- declare const MAXIMUM_CACHE_TIME: number;
4
- declare const defaultOptions: LimitedCacheOptionsReadonly;
5
- export { CURRENT_META_VERSION, MAXIMUM_CACHE_TIME, defaultOptions };
@@ -1,12 +0,0 @@
1
- declare const limitedCacheUtil: {
2
- init: <ItemType = any>(optionsOrCacheMeta?: Partial<import("..").LimitedCacheOptionsFull> | import("..").LimitedCacheMeta<ItemType> | null | undefined) => import("..").LimitedCacheMeta<ItemType>;
3
- get: <ItemType_1 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_1>, cacheKey: string) => ItemType_1 | undefined;
4
- getAll: <ItemType_2 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_2>) => Record<string, ItemType_2>;
5
- has: <ItemType_3 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_3>, cacheKey: string) => boolean;
6
- set: <ItemType_4 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_4>, cacheKey: string, item: ItemType_4) => import("..").LimitedCacheMeta<ItemType_4>;
7
- remove: <ItemType_5 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_5>, cacheKey: string) => import("..").LimitedCacheMeta<ItemType_5>;
8
- reset: <ItemType_6 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_6>) => import("..").LimitedCacheMeta<ItemType_6>;
9
- doMaintenance: <ItemType_7 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_7>) => import("..").LimitedCacheMeta<ItemType_7>;
10
- setOptions: <ItemType_8 = any>(cacheMeta: import("..").LimitedCacheMeta<ItemType_8>, options: import("..").LimitedCacheOptions) => Readonly<import("..").LimitedCacheOptionsFull>;
11
- };
12
- export { limitedCacheUtil };
@@ -1,13 +0,0 @@
1
- import { LimitedCacheOptions, LimitedCacheOptionsReadonly, LimitedCacheMeta, LimitedCacheOptionsFull } from '../types';
2
- declare const isCacheMeta: (cacheMeta: LimitedCacheMeta) => boolean;
3
- declare const upgradeCacheMeta: (cacheMeta: LimitedCacheMeta) => void;
4
- declare const lowLevelSetOptions: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, options: LimitedCacheOptions) => LimitedCacheOptionsReadonly;
5
- declare const lowLevelInit: <ItemType = any>(optionsOrCacheMeta?: Partial<LimitedCacheOptionsFull> | LimitedCacheMeta<ItemType> | null | undefined) => LimitedCacheMeta<ItemType>;
6
- declare const lowLevelDoMaintenance: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>) => LimitedCacheMeta<ItemType>;
7
- declare const lowLevelHas: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string) => boolean;
8
- declare const lowLevelGetOne: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string) => ItemType | undefined;
9
- declare const lowLevelGetAll: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>) => Record<string, ItemType>;
10
- declare const lowLevelSet: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string, item: ItemType) => LimitedCacheMeta<ItemType>;
11
- declare const lowLevelRemove: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>, cacheKey: string) => LimitedCacheMeta<ItemType>;
12
- declare const lowLevelReset: <ItemType = any>(cacheMeta: LimitedCacheMeta<ItemType>) => LimitedCacheMeta<ItemType>;
13
- export { isCacheMeta, upgradeCacheMeta, lowLevelInit, lowLevelGetOne, lowLevelGetAll, lowLevelHas, lowLevelSet, lowLevelRemove, lowLevelReset, lowLevelDoMaintenance, lowLevelSetOptions, };
@@ -1,6 +0,0 @@
1
- export * from './core/defaultOptions';
2
- export * from './core/LimitedCache';
3
- export * from './core/LimitedCacheObject';
4
- export * from './core/limitedCacheUtil';
5
- export * from './core/lowLevelFunctions';
6
- export * from './types';
@@ -1,60 +0,0 @@
1
- export declare type DefaultItemType = any;
2
- export interface LimitedCacheOptionsFull {
3
- /** Items will be removed to keep the cache within the maxCacheSize limit */
4
- maxCacheSize: number;
5
- /** Items will be removed and never returned if they were set more than maxCacheTime milliseconds ago */
6
- maxCacheTime: number;
7
- /** (dev only) A warning will be emitted if an item rotates out of the cache before this many milliseconds have passed, to indicate the size is too small */
8
- warnIfItemPurgedBeforeTime: number;
9
- /** (private) Internal cleanup of old keys will be performed after this many operations */
10
- opLimit: number;
11
- /** (private) Internal optimization to adjust how much searching will be done to find expired items, to avoid being O(n) */
12
- scanLimit: number;
13
- }
14
- export declare type LimitedCacheOptions = Partial<LimitedCacheOptionsFull> | null;
15
- export declare type LimitedCacheOptionsReadonly = Readonly<LimitedCacheOptionsFull>;
16
- export interface LimitedCacheInstance<ItemType = DefaultItemType> {
17
- /** Return the requested item, if it has not expired */
18
- get: (cacheKey: string) => ItemType | undefined;
19
- /** Return all non-expired items */
20
- getAll: () => Record<string, ItemType>;
21
- /** Indicate whether or not the requested item is present and has not expired */
22
- has: (cacheKey: string) => boolean;
23
- /** Add the item to the cache, or update its timestamp if it already exists */
24
- set: (cacheKey: string, item: ItemType) => ItemType;
25
- /** Remove the requested item from the cache, if necessary */
26
- remove: (cacheKey: string) => true;
27
- /** Remove all items and all timestamps from the cache */
28
- reset: () => LimitedCacheMeta<ItemType>;
29
- /** Return a serializable representation of the cache internals, suitable for long-term storage */
30
- getCacheMeta: () => LimitedCacheMeta<ItemType>;
31
- /** Return the cache's current values for all options */
32
- getOptions: () => LimitedCacheOptionsFull;
33
- /** Update one or more of the cache's options */
34
- setOptions: (newOptions: LimitedCacheOptions) => LimitedCacheOptionsReadonly;
35
- /** Reduces cache size by cleaning up old keys and expired items */
36
- doMaintenance: () => LimitedCacheMeta<ItemType>;
37
- }
38
- export interface LimitedCacheObjectInstance<ItemType = DefaultItemType> {
39
- [key: string]: ItemType;
40
- }
41
- /**
42
- * A serializable representation of the cache internals, suitable for long-term storage
43
- */
44
- export interface LimitedCacheMeta<ItemType = DefaultItemType> {
45
- /** Schema version: old versions will be upgraded if possible, or a warning will be emitted if not */
46
- limitedCacheMetaVersion: number;
47
- /** Options to control cache size, time, and behavior */
48
- options: LimitedCacheOptionsReadonly;
49
- /** The values in the cache, stored by key. Will include old keys not yet garbage collected */
50
- cache: Record<string, ItemType | undefined>;
51
- /** List of keys that have been set, in chronological order. Used to find cache items most likely to be expired */
52
- keyList: Array<string>;
53
- /** The [setTime, expirationTime] for each key that has been set. Removed on unset. */
54
- keyInfo: Record<string, [
55
- number,
56
- number
57
- ] | undefined>;
58
- /** Number of operations remaining until internal cleanup of old keys is performed. Based on options.opLimit */
59
- opsLeft: number;
60
- }