@twin.org/core 0.9.2-next.9 → 0.9.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/helpers/jsonHelper.js +1 -2
- package/dist/es/helpers/jsonHelper.js.map +1 -1
- package/dist/es/index.js +2 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/coerceType.js +5 -1
- package/dist/es/models/coerceType.js.map +1 -1
- package/dist/es/utils/coerce.js +28 -1
- package/dist/es/utils/coerce.js.map +1 -1
- package/dist/es/utils/is.js +27 -4
- package/dist/es/utils/is.js.map +1 -1
- package/dist/es/utils/lfuCache.js +380 -0
- package/dist/es/utils/lfuCache.js.map +1 -0
- package/dist/es/utils/lruCache.js +271 -0
- package/dist/es/utils/lruCache.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models/coerceType.d.ts +4 -0
- package/dist/types/utils/coerce.d.ts +6 -0
- package/dist/types/utils/lfuCache.d.ts +100 -0
- package/dist/types/utils/lruCache.d.ts +97 -0
- package/docs/changelog.md +148 -0
- package/docs/reference/classes/Coerce.md +28 -0
- package/docs/reference/classes/LfuCache.md +265 -0
- package/docs/reference/classes/LruCache.md +262 -0
- package/docs/reference/index.md +2 -0
- package/docs/reference/variables/CoerceType.md +6 -0
- package/package.json +2 -2
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,153 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.3-next.1](https://github.com/iotaledger/twin-framework/compare/core-v0.9.3-next.0...core-v0.9.3-next.1) (2026-08-26)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#206](https://github.com/iotaledger/twin-framework/issues/206)) ([ef0d4ee](https://github.com/iotaledger/twin-framework/commit/ef0d4ee11a4f5fc6cc6f52a4958ce905c04ee13b))
|
|
9
|
+
* add duration support ([#362](https://github.com/iotaledger/twin-framework/issues/362)) ([24dbe8b](https://github.com/iotaledger/twin-framework/commit/24dbe8b208eb127a52024cb219d31d27731e9ae3))
|
|
10
|
+
* add factory.createIfExists ([aad5a53](https://github.com/iotaledger/twin-framework/commit/aad5a53cef1b1c2e04344ea46244d41e371dff9b))
|
|
11
|
+
* add Factory.getFactory ([ad6cd2d](https://github.com/iotaledger/twin-framework/commit/ad6cd2d30351c145c70212f8cce1b66d5e8a5235))
|
|
12
|
+
* add guard.dateString ([#335](https://github.com/iotaledger/twin-framework/issues/335)) ([a26a166](https://github.com/iotaledger/twin-framework/commit/a26a166eb1f62ece05b2432730cb7354feacecfc))
|
|
13
|
+
* add health method to components ([a88016d](https://github.com/iotaledger/twin-framework/commit/a88016d90d172413e5bc5238dc1b3e35f82fcc2c))
|
|
14
|
+
* add isDefault option to factory registration ([a8a700b](https://github.com/iotaledger/twin-framework/commit/a8a700bb8ddaf7dd5097869a358b8fc5f7c40ce7))
|
|
15
|
+
* add lru and lft cache ([#449](https://github.com/iotaledger/twin-framework/issues/449)) ([67d741e](https://github.com/iotaledger/twin-framework/commit/67d741eab3b89556e3c55053b5a473a4c1592fed))
|
|
16
|
+
* add mutex ([#316](https://github.com/iotaledger/twin-framework/issues/316)) ([1027e5a](https://github.com/iotaledger/twin-framework/commit/1027e5ac77aa9804178b4253abdeefd6f1c3d521))
|
|
17
|
+
* add objectHelper.split ([386830a](https://github.com/iotaledger/twin-framework/commit/386830a77f8e842a5b119be0983708e042c3b14b))
|
|
18
|
+
* add partial second support ([39bf087](https://github.com/iotaledger/twin-framework/commit/39bf087ddc113a9bf73e0d0e99f738f6f60c2f2d))
|
|
19
|
+
* add single occurrence array type ([e890e43](https://github.com/iotaledger/twin-framework/commit/e890e4399e75ae5097f3ad8b1007321cbb1ed4ac))
|
|
20
|
+
* add single occurrence array type ([#245](https://github.com/iotaledger/twin-framework/issues/245)) ([771dc78](https://github.com/iotaledger/twin-framework/commit/771dc78025b5546c9c9681be9494a76ab71171c6))
|
|
21
|
+
* add support for health i18n validation ([7a286dd](https://github.com/iotaledger/twin-framework/commit/7a286ddb0c1bfa498bf3a77126cd589042bad6de))
|
|
22
|
+
* add teardown to IComponent interface ([32c173c](https://github.com/iotaledger/twin-framework/commit/32c173cda115c20d3b4cee14b8a29cdc08e91555))
|
|
23
|
+
* add teardown to IComponent interface ([98ce864](https://github.com/iotaledger/twin-framework/commit/98ce8648e709310c4435de334825b381fb4e32cb))
|
|
24
|
+
* add typeName method to factory ([699fcbd](https://github.com/iotaledger/twin-framework/commit/699fcbd1168228401ddb81fdacb959b8cdc4206a))
|
|
25
|
+
* add uuidv7 support ([#219](https://github.com/iotaledger/twin-framework/issues/219)) ([916c657](https://github.com/iotaledger/twin-framework/commit/916c657d270ce99fafe554233739fdd9ca28635b))
|
|
26
|
+
* add wildcard support to the envhelper ([c064d46](https://github.com/iotaledger/twin-framework/commit/c064d46d36bbee8022a741b985d2b64c8f9572e4))
|
|
27
|
+
* adding link header helper ([#225](https://github.com/iotaledger/twin-framework/issues/225)) ([703c072](https://github.com/iotaledger/twin-framework/commit/703c0725aceac6b6ec0c4fa729ef832d12fb3fd7))
|
|
28
|
+
* additional nameof operators ([a5aab60](https://github.com/iotaledger/twin-framework/commit/a5aab60bf66a86f1b7ff8af7c4f044cb03706d50))
|
|
29
|
+
* bump version ([c5354fa](https://github.com/iotaledger/twin-framework/commit/c5354fa906f4493c70f2642a9175a66780a10636))
|
|
30
|
+
* coerce array ([#452](https://github.com/iotaledger/twin-framework/issues/452)) ([2019567](https://github.com/iotaledger/twin-framework/commit/20195673a65fe7179272ac84f37dc927218c128a))
|
|
31
|
+
* concurrency in SharedStore ([#388](https://github.com/iotaledger/twin-framework/issues/388)) ([0610198](https://github.com/iotaledger/twin-framework/commit/0610198ba482273c3f6ba918e34f5875a3659571))
|
|
32
|
+
* configurable timeout for mutex ([2087e04](https://github.com/iotaledger/twin-framework/commit/2087e04464a110a3f009fbc8b066696ed6784fc2))
|
|
33
|
+
* env helper conversion methods ([e8c607e](https://github.com/iotaledger/twin-framework/commit/e8c607e59f6f79d4b1d562e9313babe348778835))
|
|
34
|
+
* expand error params to accept properties ([032e9fd](https://github.com/iotaledger/twin-framework/commit/032e9fd1388e457cde32ca1005dfe014a5a9c077))
|
|
35
|
+
* factory create and integrity ([#235](https://github.com/iotaledger/twin-framework/issues/235)) ([9f98b99](https://github.com/iotaledger/twin-framework/commit/9f98b99daf46eb365346fae49cc4ffba63e74cb3))
|
|
36
|
+
* health status grouping ([5007c29](https://github.com/iotaledger/twin-framework/commit/5007c29fe4123fe56f754450b993dbe5dc32a057))
|
|
37
|
+
* improve async cache edge cases ([4e57a6e](https://github.com/iotaledger/twin-framework/commit/4e57a6ec4113533b0ea903eae7d469200fa1348c))
|
|
38
|
+
* improve error formatting ([#313](https://github.com/iotaledger/twin-framework/issues/313)) ([5a19623](https://github.com/iotaledger/twin-framework/commit/5a196231bcbf088bf9ba92a93b7478d3b8c5593f))
|
|
39
|
+
* improve Is.function and ModuleHelper.getModuleMethod signatures ([ecf968b](https://github.com/iotaledger/twin-framework/commit/ecf968b02934b3676be4bf7cd2d1e7f8e7af6ce2))
|
|
40
|
+
* improve Is.function definition to retain types ([f20b6b0](https://github.com/iotaledger/twin-framework/commit/f20b6b0dd16e74b75dc359be72b05989305c6410))
|
|
41
|
+
* improve signatures ([45a7d58](https://github.com/iotaledger/twin-framework/commit/45a7d58baa5b6abc8c0735656f393d402fabb4ad))
|
|
42
|
+
* improve signatures ([cdd24be](https://github.com/iotaledger/twin-framework/commit/cdd24be6fb898d33955b6f2f93c3ddbd73582269))
|
|
43
|
+
* improve signatures ([2041ae2](https://github.com/iotaledger/twin-framework/commit/2041ae214cbd8d472d5e8be8d3403cd06a114040))
|
|
44
|
+
* improve signatures ([d8a0ee1](https://github.com/iotaledger/twin-framework/commit/d8a0ee16542134a3f8b0653065239f42045125b4))
|
|
45
|
+
* improve signatures ([1d084c5](https://github.com/iotaledger/twin-framework/commit/1d084c58c7eb41ae50b0ce80ce57e48a22dd3102))
|
|
46
|
+
* improve signatures ([#287](https://github.com/iotaledger/twin-framework/issues/287)) ([c9f38f0](https://github.com/iotaledger/twin-framework/commit/c9f38f00e1cea8759e1105b41872a650c66c00f4))
|
|
47
|
+
* improved coercion ([fcc7d98](https://github.com/iotaledger/twin-framework/commit/fcc7d9826f5405be5e3b5414ea53be42f974f9d5))
|
|
48
|
+
* is and coerce accept duration object ([51dffa1](https://github.com/iotaledger/twin-framework/commit/51dffa18066eb86a14c700d90d3c1bd8b322c0fc))
|
|
49
|
+
* linting and dependency update ([1c428ef](https://github.com/iotaledger/twin-framework/commit/1c428efe0391c52632962847d8dad68bd8e5dd00))
|
|
50
|
+
* linting and dependency update ([676b4e9](https://github.com/iotaledger/twin-framework/commit/676b4e9d9bce158065200bbf875bb31da81d166d))
|
|
51
|
+
* locales validation ([#197](https://github.com/iotaledger/twin-framework/issues/197)) ([55fdadb](https://github.com/iotaledger/twin-framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
|
|
52
|
+
* move health support to api repo ([#435](https://github.com/iotaledger/twin-framework/issues/435)) ([867f766](https://github.com/iotaledger/twin-framework/commit/867f766afc86607bec6b5cf9c3ab5bd5c41d0b3c))
|
|
53
|
+
* mutex safe usage in browser ([#339](https://github.com/iotaledger/twin-framework/issues/339)) ([02d409f](https://github.com/iotaledger/twin-framework/commit/02d409f211e91267964208d58a27f29791715086))
|
|
54
|
+
* nodeIdentity optional in IComponent methods ([c78dc17](https://github.com/iotaledger/twin-framework/commit/c78dc17f4357d3e1ae40e415f468d3eae13e81f4))
|
|
55
|
+
* optimistic locking version property for schemas ([#443](https://github.com/iotaledger/twin-framework/issues/443)) ([1b90987](https://github.com/iotaledger/twin-framework/commit/1b909875dc915a0ec133d8424d013ae7e4ddfb48))
|
|
56
|
+
* shared object buffer ([#355](https://github.com/iotaledger/twin-framework/issues/355)) ([70d82ea](https://github.com/iotaledger/twin-framework/commit/70d82ea8f43f01aa840ae90ee0b1f23b064a07c6))
|
|
57
|
+
* simplify factory options ([7f85a85](https://github.com/iotaledger/twin-framework/commit/7f85a8553dd3008364e8e1104f2e6f6b6595d77e))
|
|
58
|
+
* simplify StringHelper signature ([0390403](https://github.com/iotaledger/twin-framework/commit/039040344952f91ee3c671249bc0e1c8f3b38e17))
|
|
59
|
+
* typescript 6 update ([1d10f31](https://github.com/iotaledger/twin-framework/commit/1d10f31e6516ec622773f45e88af82fe749b384a))
|
|
60
|
+
* update dependencies ([4da77ab](https://github.com/iotaledger/twin-framework/commit/4da77ab30f499e52825ac5a76f51436ceb59c26e))
|
|
61
|
+
* urn and header helper extensions ([#395](https://github.com/iotaledger/twin-framework/issues/395)) ([5976756](https://github.com/iotaledger/twin-framework/commit/5976756886d22e5063671052abc4dfa04ce23a53))
|
|
62
|
+
* urn random switched to using uuidv7 ([606c9a2](https://github.com/iotaledger/twin-framework/commit/606c9a2ed68a10fc7fc2bc5f93388c1b71033154))
|
|
63
|
+
* urn random switched to using uuidv7 ([6a29f8b](https://github.com/iotaledger/twin-framework/commit/6a29f8bd573d06992b7eaa027b1daf4c2a2e1e85))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Bug Fixes
|
|
67
|
+
|
|
68
|
+
* async thread lock ([97a96a5](https://github.com/iotaledger/twin-framework/commit/97a96a57f60c7b45a0ccbbfa1c43199b6e7512f9))
|
|
69
|
+
* coerce and includes ([#429](https://github.com/iotaledger/twin-framework/issues/429)) ([98c9132](https://github.com/iotaledger/twin-framework/commit/98c9132316c0393ede9d6e634bbae9e5ece2d6b9))
|
|
70
|
+
* ensure __decorate is defined for decorators ([103a563](https://github.com/iotaledger/twin-framework/commit/103a563ce01ebdef6240d2e590e7b026e8692684))
|
|
71
|
+
* improve exception handling in asyncCache ([c81b29b](https://github.com/iotaledger/twin-framework/commit/c81b29b660b152d2f0757d323430287e6491bf59))
|
|
72
|
+
* improve jsdoc comments ([f7c8e43](https://github.com/iotaledger/twin-framework/commit/f7c8e43fab9803dffa6461950d5b9979e25bcd24))
|
|
73
|
+
* iso 8601 checks ([#409](https://github.com/iotaledger/twin-framework/issues/409)) ([4427101](https://github.com/iotaledger/twin-framework/commit/442710109b63ec67ca5ee7cb948df742500d0151))
|
|
74
|
+
* large regex tests ([#463](https://github.com/iotaledger/twin-framework/issues/463)) ([f4a3a5c](https://github.com/iotaledger/twin-framework/commit/f4a3a5c95619abed1e16791e54e884d4ffc503a8))
|
|
75
|
+
* linting ([b77511d](https://github.com/iotaledger/twin-framework/commit/b77511de8781707088b1beb4c92f12d7d6e0fd5f))
|
|
76
|
+
* mutex locking ([d5af3c1](https://github.com/iotaledger/twin-framework/commit/d5af3c1e66070f86408ba1410809689c6d22958b))
|
|
77
|
+
* number coercion wrongly accepts alpha ([c04c1af](https://github.com/iotaledger/twin-framework/commit/c04c1af24697b6c92a180a71c0722c5673313360))
|
|
78
|
+
* number coercion wrongly accepts alpha ([dd5b193](https://github.com/iotaledger/twin-framework/commit/dd5b193c2501f6d30ca94aa0fc30a6edfe405e6f))
|
|
79
|
+
* pick non iterable keys ([399399a](https://github.com/iotaledger/twin-framework/commit/399399abfb8947c4eb235df527532ffe186986b3))
|
|
80
|
+
* prevent TOCTOU race in Mutex.getOrFetchLock for concurrent async callers ([#343](https://github.com/iotaledger/twin-framework/issues/343)) ([5238ad1](https://github.com/iotaledger/twin-framework/commit/5238ad1a68e24c69162204b02030c6686c15e9f4))
|
|
81
|
+
* remove misleading undefined from AsyncCache return type ([05b3291](https://github.com/iotaledger/twin-framework/commit/05b32914e03a63c7daf7b77952a2ebedb7ca7f6b))
|
|
82
|
+
* settle AsyncCache waiters correctly when a request resolves undefined or null ([#401](https://github.com/iotaledger/twin-framework/issues/401)) ([6ae3f8a](https://github.com/iotaledger/twin-framework/commit/6ae3f8aca688ca76d93ec3964178a3b1a8895453))
|
|
83
|
+
* time coercion ([8ac43f8](https://github.com/iotaledger/twin-framework/commit/8ac43f85fbd521ff54786d92df3e432d7f738b0c))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Dependencies
|
|
87
|
+
|
|
88
|
+
* The following workspace dependencies were updated
|
|
89
|
+
* dependencies
|
|
90
|
+
* @twin.org/nameof bumped from 0.9.3-next.0 to 0.9.3-next.1
|
|
91
|
+
* devDependencies
|
|
92
|
+
* @twin.org/nameof-transformer bumped from 0.9.3-next.0 to 0.9.3-next.1
|
|
93
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.3-next.0 to 0.9.3-next.1
|
|
94
|
+
|
|
95
|
+
## [0.9.2](https://github.com/iotaledger/twin-framework/compare/core-v0.9.2...core-v0.9.2) (2026-08-24)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### Features
|
|
99
|
+
|
|
100
|
+
* release to production ([b24cba1](https://github.com/iotaledger/twin-framework/commit/b24cba1b6a969278d638e632590602ec881e49fb))
|
|
101
|
+
* release to production ([787287d](https://github.com/iotaledger/twin-framework/commit/787287d06ea8319657401589d61fff369310c422))
|
|
102
|
+
* release to production ([53f4843](https://github.com/iotaledger/twin-framework/commit/53f484326b2851d7a506d2620db24c4a65cee7b3))
|
|
103
|
+
* release to production ([56cda4d](https://github.com/iotaledger/twin-framework/commit/56cda4da93e978c5be19ec7cfd421ae2a7fe4147))
|
|
104
|
+
* release to production ([f7c6586](https://github.com/iotaledger/twin-framework/commit/f7c6586f6976b903b647b4c5ac5ad9421e0c9051))
|
|
105
|
+
* release to production ([829d53d](https://github.com/iotaledger/twin-framework/commit/829d53d3953b1e1b40b0243c04cfdfd3842aac7b))
|
|
106
|
+
* release to production ([5cf3a76](https://github.com/iotaledger/twin-framework/commit/5cf3a76a09eff2e6414d0cba846c7c37400a11d6))
|
|
107
|
+
* release to production ([#330](https://github.com/iotaledger/twin-framework/issues/330)) ([d73f565](https://github.com/iotaledger/twin-framework/commit/d73f565588d156d23ef49b2a5718973756f7a696))
|
|
108
|
+
* release to production ([#382](https://github.com/iotaledger/twin-framework/issues/382)) ([bbed01a](https://github.com/iotaledger/twin-framework/commit/bbed01a605ee9724bda77a0f7feab249118c2d90))
|
|
109
|
+
* release to production ([#417](https://github.com/iotaledger/twin-framework/issues/417)) ([59727e7](https://github.com/iotaledger/twin-framework/commit/59727e73903a137310ca48fe469189cf29879cb9))
|
|
110
|
+
* release to production ([#459](https://github.com/iotaledger/twin-framework/issues/459)) ([e26e2d9](https://github.com/iotaledger/twin-framework/commit/e26e2d9a88767364c32494c45232033447b26e22))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### Miscellaneous Chores
|
|
114
|
+
|
|
115
|
+
* release to production ([63cae24](https://github.com/iotaledger/twin-framework/commit/63cae2401f6c11f93b2a01260b665064e8bd28e0))
|
|
116
|
+
|
|
117
|
+
## [0.9.2-next.11](https://github.com/iotaledger/twin-framework/compare/core-v0.9.2-next.10...core-v0.9.2-next.11) (2026-08-20)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Features
|
|
121
|
+
|
|
122
|
+
* coerce array ([#452](https://github.com/iotaledger/twin-framework/issues/452)) ([2019567](https://github.com/iotaledger/twin-framework/commit/20195673a65fe7179272ac84f37dc927218c128a))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Dependencies
|
|
126
|
+
|
|
127
|
+
* The following workspace dependencies were updated
|
|
128
|
+
* dependencies
|
|
129
|
+
* @twin.org/nameof bumped from 0.9.2-next.10 to 0.9.2-next.11
|
|
130
|
+
* devDependencies
|
|
131
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.10 to 0.9.2-next.11
|
|
132
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.10 to 0.9.2-next.11
|
|
133
|
+
|
|
134
|
+
## [0.9.2-next.10](https://github.com/iotaledger/twin-framework/compare/core-v0.9.2-next.9...core-v0.9.2-next.10) (2026-08-11)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### Features
|
|
138
|
+
|
|
139
|
+
* add lru and lft cache ([#449](https://github.com/iotaledger/twin-framework/issues/449)) ([67d741e](https://github.com/iotaledger/twin-framework/commit/67d741eab3b89556e3c55053b5a473a4c1592fed))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
### Dependencies
|
|
143
|
+
|
|
144
|
+
* The following workspace dependencies were updated
|
|
145
|
+
* dependencies
|
|
146
|
+
* @twin.org/nameof bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
147
|
+
* devDependencies
|
|
148
|
+
* @twin.org/nameof-transformer bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
149
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.2-next.9 to 0.9.2-next.10
|
|
150
|
+
|
|
3
151
|
## [0.9.2-next.9](https://github.com/iotaledger/twin-framework/compare/core-v0.9.2-next.8...core-v0.9.2-next.9) (2026-08-10)
|
|
4
152
|
|
|
5
153
|
|
|
@@ -214,6 +214,34 @@ The duration object, or undefined if the value cannot be coerced.
|
|
|
214
214
|
|
|
215
215
|
***
|
|
216
216
|
|
|
217
|
+
### array() {#array}
|
|
218
|
+
|
|
219
|
+
> `static` **array**\<`T`\>(`value`): `T`[] \| `undefined`
|
|
220
|
+
|
|
221
|
+
Coerce the value to an array.
|
|
222
|
+
|
|
223
|
+
#### Type Parameters
|
|
224
|
+
|
|
225
|
+
##### T
|
|
226
|
+
|
|
227
|
+
`T` = `unknown`
|
|
228
|
+
|
|
229
|
+
#### Parameters
|
|
230
|
+
|
|
231
|
+
##### value
|
|
232
|
+
|
|
233
|
+
`unknown`
|
|
234
|
+
|
|
235
|
+
The value to coerce.
|
|
236
|
+
|
|
237
|
+
#### Returns
|
|
238
|
+
|
|
239
|
+
`T`[] \| `undefined`
|
|
240
|
+
|
|
241
|
+
The coerced array, or undefined if the value cannot be coerced.
|
|
242
|
+
|
|
243
|
+
***
|
|
244
|
+
|
|
217
245
|
### object() {#object}
|
|
218
246
|
|
|
219
247
|
> `static` **object**\<`T`\>(`value`): `T` \| `undefined`
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# Class: LfuCache\<T\>
|
|
2
|
+
|
|
3
|
+
A fixed-capacity LFU cache with time-to-idle eviction.
|
|
4
|
+
|
|
5
|
+
Entries are removed in two ways:
|
|
6
|
+
- Capacity eviction: when the cache is full the least-frequently-used entry is removed first.
|
|
7
|
+
Ties in frequency are broken by recency the least-recently-used entry among those with the
|
|
8
|
+
minimum frequency is evicted.
|
|
9
|
+
- TTI eviction: a background timer sweeps idle entries every ttiMs milliseconds.
|
|
10
|
+
The timer only runs while there are entries; it stops automatically when the cache empties.
|
|
11
|
+
|
|
12
|
+
`get` and `set` increment an entry's access frequency and reset its idle timer.
|
|
13
|
+
`has` and `keys` are pure peeks they evict idle entries but do not affect frequency or TTI.
|
|
14
|
+
Call `destroy` when the cache is no longer needed to stop the background timer.
|
|
15
|
+
|
|
16
|
+
## Type Parameters
|
|
17
|
+
|
|
18
|
+
### T
|
|
19
|
+
|
|
20
|
+
`T`
|
|
21
|
+
|
|
22
|
+
## Constructors
|
|
23
|
+
|
|
24
|
+
### Constructor
|
|
25
|
+
|
|
26
|
+
> **new LfuCache**\<`T`\>(`options?`): `LfuCache`\<`T`\>
|
|
27
|
+
|
|
28
|
+
Create a new instance of LfuCache.
|
|
29
|
+
|
|
30
|
+
#### Parameters
|
|
31
|
+
|
|
32
|
+
##### options?
|
|
33
|
+
|
|
34
|
+
The cache options.
|
|
35
|
+
|
|
36
|
+
###### capacity?
|
|
37
|
+
|
|
38
|
+
`number`
|
|
39
|
+
|
|
40
|
+
Maximum number of entries. Defaults to 1000. Must be a positive integer.
|
|
41
|
+
|
|
42
|
+
###### ttiMs?
|
|
43
|
+
|
|
44
|
+
`number`
|
|
45
|
+
|
|
46
|
+
Time-to-idle in milliseconds. Defaults to 10000. Must be a positive integer.
|
|
47
|
+
|
|
48
|
+
###### mutexTimeoutMs?
|
|
49
|
+
|
|
50
|
+
`number`
|
|
51
|
+
|
|
52
|
+
Maximum time in milliseconds to wait for getOrSet mutex acquisition.
|
|
53
|
+
|
|
54
|
+
#### Returns
|
|
55
|
+
|
|
56
|
+
`LfuCache`\<`T`\>
|
|
57
|
+
|
|
58
|
+
#### Throws
|
|
59
|
+
|
|
60
|
+
ValidationError if capacity or ttiMs is not a positive integer.
|
|
61
|
+
|
|
62
|
+
## Properties
|
|
63
|
+
|
|
64
|
+
### CLASS\_NAME {#class_name}
|
|
65
|
+
|
|
66
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
67
|
+
|
|
68
|
+
Runtime name for the class.
|
|
69
|
+
|
|
70
|
+
***
|
|
71
|
+
|
|
72
|
+
### DEFAULT\_CAPACITY {#default_capacity}
|
|
73
|
+
|
|
74
|
+
> `readonly` `static` **DEFAULT\_CAPACITY**: `1000` = `1000`
|
|
75
|
+
|
|
76
|
+
Default capacity.
|
|
77
|
+
|
|
78
|
+
***
|
|
79
|
+
|
|
80
|
+
### DEFAULT\_TTI\_MS {#default_tti_ms}
|
|
81
|
+
|
|
82
|
+
> `readonly` `static` **DEFAULT\_TTI\_MS**: `10000` = `10000`
|
|
83
|
+
|
|
84
|
+
Default time-to-idle in milliseconds.
|
|
85
|
+
|
|
86
|
+
## Methods
|
|
87
|
+
|
|
88
|
+
### count() {#count}
|
|
89
|
+
|
|
90
|
+
> **count**(): `number`
|
|
91
|
+
|
|
92
|
+
The number of entries currently held in the cache.
|
|
93
|
+
|
|
94
|
+
#### Returns
|
|
95
|
+
|
|
96
|
+
`number`
|
|
97
|
+
|
|
98
|
+
The number of entries in the cache.
|
|
99
|
+
|
|
100
|
+
***
|
|
101
|
+
|
|
102
|
+
### get() {#get}
|
|
103
|
+
|
|
104
|
+
> **get**(`key`): `T` \| `undefined`
|
|
105
|
+
|
|
106
|
+
Get a value from the cache.
|
|
107
|
+
Returns undefined if the key is absent or the entry has idled out.
|
|
108
|
+
A successful hit increments the entry's frequency and resets its idle timer.
|
|
109
|
+
|
|
110
|
+
#### Parameters
|
|
111
|
+
|
|
112
|
+
##### key
|
|
113
|
+
|
|
114
|
+
`string`
|
|
115
|
+
|
|
116
|
+
The key to retrieve.
|
|
117
|
+
|
|
118
|
+
#### Returns
|
|
119
|
+
|
|
120
|
+
`T` \| `undefined`
|
|
121
|
+
|
|
122
|
+
The cached value, or undefined on a miss or idle eviction.
|
|
123
|
+
|
|
124
|
+
***
|
|
125
|
+
|
|
126
|
+
### set() {#set}
|
|
127
|
+
|
|
128
|
+
> **set**(`key`, `value`): `void`
|
|
129
|
+
|
|
130
|
+
Store a value in the cache.
|
|
131
|
+
If the key already exists its value and frequency are updated.
|
|
132
|
+
When the cache is at capacity, idle entries are swept first; if it is still full the
|
|
133
|
+
least-frequently-used entry is evicted (LRU among ties).
|
|
134
|
+
|
|
135
|
+
#### Parameters
|
|
136
|
+
|
|
137
|
+
##### key
|
|
138
|
+
|
|
139
|
+
`string`
|
|
140
|
+
|
|
141
|
+
The key to store.
|
|
142
|
+
|
|
143
|
+
##### value
|
|
144
|
+
|
|
145
|
+
`T`
|
|
146
|
+
|
|
147
|
+
The value to cache.
|
|
148
|
+
|
|
149
|
+
#### Returns
|
|
150
|
+
|
|
151
|
+
`void`
|
|
152
|
+
|
|
153
|
+
***
|
|
154
|
+
|
|
155
|
+
### getOrSet() {#getorset}
|
|
156
|
+
|
|
157
|
+
> **getOrSet**(`key`, `valueFactory`): `Promise`\<`T`\>
|
|
158
|
+
|
|
159
|
+
Atomically get an existing value or create and store it once using an async factory.
|
|
160
|
+
Concurrent calls for the same key are serialized via a mutex.
|
|
161
|
+
|
|
162
|
+
#### Parameters
|
|
163
|
+
|
|
164
|
+
##### key
|
|
165
|
+
|
|
166
|
+
`string`
|
|
167
|
+
|
|
168
|
+
The key to get or create.
|
|
169
|
+
|
|
170
|
+
##### valueFactory
|
|
171
|
+
|
|
172
|
+
() => `Promise`\<`T`\>
|
|
173
|
+
|
|
174
|
+
Async callback used to build a value when the key is absent.
|
|
175
|
+
|
|
176
|
+
#### Returns
|
|
177
|
+
|
|
178
|
+
`Promise`\<`T`\>
|
|
179
|
+
|
|
180
|
+
The existing or newly created value.
|
|
181
|
+
|
|
182
|
+
***
|
|
183
|
+
|
|
184
|
+
### has() {#has}
|
|
185
|
+
|
|
186
|
+
> **has**(`key`): `boolean`
|
|
187
|
+
|
|
188
|
+
Check whether a key exists in the cache and has not idled out.
|
|
189
|
+
Idle entries are evicted on peek, but a live entry's frequency and TTI are not updated.
|
|
190
|
+
|
|
191
|
+
#### Parameters
|
|
192
|
+
|
|
193
|
+
##### key
|
|
194
|
+
|
|
195
|
+
`string`
|
|
196
|
+
|
|
197
|
+
The key to test.
|
|
198
|
+
|
|
199
|
+
#### Returns
|
|
200
|
+
|
|
201
|
+
`boolean`
|
|
202
|
+
|
|
203
|
+
True if the key is present and not idle.
|
|
204
|
+
|
|
205
|
+
***
|
|
206
|
+
|
|
207
|
+
### keys() {#keys}
|
|
208
|
+
|
|
209
|
+
> **keys**(): `string`[]
|
|
210
|
+
|
|
211
|
+
Return all keys for entries that have not idled out.
|
|
212
|
+
Idle entries encountered during iteration are evicted.
|
|
213
|
+
Keys are returned in ascending frequency order; within the same frequency, LRU first.
|
|
214
|
+
|
|
215
|
+
#### Returns
|
|
216
|
+
|
|
217
|
+
`string`[]
|
|
218
|
+
|
|
219
|
+
An array of live keys ordered from least-frequently-used to most-frequently-used.
|
|
220
|
+
|
|
221
|
+
***
|
|
222
|
+
|
|
223
|
+
### delete() {#delete}
|
|
224
|
+
|
|
225
|
+
> **delete**(`key`): `void`
|
|
226
|
+
|
|
227
|
+
Remove an entry from the cache.
|
|
228
|
+
Cancels the background timer if the cache becomes empty.
|
|
229
|
+
|
|
230
|
+
#### Parameters
|
|
231
|
+
|
|
232
|
+
##### key
|
|
233
|
+
|
|
234
|
+
`string`
|
|
235
|
+
|
|
236
|
+
The key to remove.
|
|
237
|
+
|
|
238
|
+
#### Returns
|
|
239
|
+
|
|
240
|
+
`void`
|
|
241
|
+
|
|
242
|
+
***
|
|
243
|
+
|
|
244
|
+
### clear() {#clear}
|
|
245
|
+
|
|
246
|
+
> **clear**(): `void`
|
|
247
|
+
|
|
248
|
+
Remove all entries from the cache and cancel the background timer.
|
|
249
|
+
|
|
250
|
+
#### Returns
|
|
251
|
+
|
|
252
|
+
`void`
|
|
253
|
+
|
|
254
|
+
***
|
|
255
|
+
|
|
256
|
+
### destroy() {#destroy}
|
|
257
|
+
|
|
258
|
+
> **destroy**(): `void`
|
|
259
|
+
|
|
260
|
+
Stop the background idle-sweep timer and release all entries.
|
|
261
|
+
The cache must not be used after this call.
|
|
262
|
+
|
|
263
|
+
#### Returns
|
|
264
|
+
|
|
265
|
+
`void`
|