@daiso-tech/core 0.24.0 → 0.26.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.
- package/README.md +3 -2
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +12 -3
- package/dist/async/utilities/lazy-promise/lazy-promise.js +37 -4
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +4 -4
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/kysely-sqlite-cache-adapter/kysely-sqlite-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +4 -4
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +5 -5
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +70 -184
- package/dist/cache/implementations/derivables/cache/cache.js +68 -185
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +11 -15
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +0 -11
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +5 -5
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +5 -5
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.js +5 -5
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_shared.d.ts +0 -7
- package/dist/event-bus/contracts/_shared.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +6 -5
- package/dist/event-bus/contracts/event-bus.contract.d.ts +21 -16
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +4 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +4 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +4 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +64 -33
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +92 -33
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +957 -201
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/lock-provider.contract.d.ts +2 -2
- package/dist/lock/contracts/lock.contract.d.ts +24 -6
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +2 -2
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +2 -2
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +90 -48
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +67 -43
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +4 -23
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +8 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +744 -11
- package/dist/lock/implementations/derivables/lock-provider/lock.js +770 -3
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +36 -5
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +10 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +1 -0
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +417 -0
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.js +4 -4
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/utilities/{constants.js → _constants.js} +1 -1
- package/dist/utilities/_constants.js.map +1 -0
- package/dist/utilities/_module-exports.d.ts +1 -1
- package/dist/utilities/_module-exports.js +1 -1
- package/dist/utilities/_module-exports.js.map +1 -1
- package/dist/utilities/contracts/_module.d.ts +0 -1
- package/dist/utilities/contracts/_module.js +0 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/functions.d.ts +3 -7
- package/dist/utilities/functions.js +3 -10
- package/dist/utilities/functions.js.map +1 -1
- package/dist/utilities/pipeline/_module.d.ts +1 -0
- package/dist/utilities/pipeline/_module.js +2 -0
- package/dist/utilities/pipeline/_module.js.map +1 -0
- package/dist/utilities/pipeline/pipeline.d.ts +45 -0
- package/dist/utilities/pipeline/pipeline.js +75 -0
- package/dist/utilities/pipeline/pipeline.js.map +1 -0
- package/dist/utilities/time-span/time-span.d.ts +3 -12
- package/dist/utilities/time-span/time-span.js +3 -6
- package/dist/utilities/time-span/time-span.js.map +1 -1
- package/dist/utilities/types.d.ts +19 -2
- package/package.json +1 -1
- package/dist/utilities/constants.js.map +0 -1
- package/dist/utilities/contracts/buildable.contract.d.ts +0 -11
- package/dist/utilities/contracts/buildable.contract.js +0 -5
- package/dist/utilities/contracts/buildable.contract.js.map +0 -1
- /package/dist/utilities/{constants.d.ts → _constants.d.ts} +0 -0
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import { KeyFoundCacheEvent, KeyNotFoundCacheEvent, KeyAddedCacheEvent, KeyUpdatedCacheEvent, KeyRemovedCacheEvent, KeyIncrementedCacheEvent, KeyDecrementedCacheEvent, KeysClearedCacheEvent, UnexpectedCacheErrorEvent, } from "../../../../cache/contracts/_module-exports.js";
|
|
5
5
|
import { KeyNotFoundCacheError, TypeCacheError, UnexpectedCacheError, } from "../../../../cache/contracts/_module-exports.js";
|
|
6
6
|
import {} from "../../../../cache/contracts/_module-exports.js";
|
|
7
|
-
import {
|
|
7
|
+
import { isObjectEmpty, resolveAsyncLazyable, resolveOneOrMoreStr, } from "../../../../utilities/_module-exports.js";
|
|
8
8
|
import { LazyPromise } from "../../../../async/_module-exports.js";
|
|
9
9
|
import { EventBus } from "../../../../event-bus/implementations/derivables/_module-exports.js";
|
|
10
|
-
import {
|
|
10
|
+
import { MemoryEventBusAdapter } from "../../../../event-bus/implementations/adapters/_module-exports.js";
|
|
11
11
|
/**
|
|
12
12
|
* <i>Cache</i> class can be derived from any <i>{@link ICacheAdapter}</i>.
|
|
13
13
|
*
|
|
@@ -31,26 +31,21 @@ export class Cache {
|
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
33
33
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
34
|
-
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
35
34
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
36
35
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
37
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
38
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
39
36
|
*
|
|
40
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
41
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
42
|
-
* });
|
|
43
37
|
* const cache: IGroupableCache = new Cache({
|
|
44
38
|
* adapter: new MemoryCacheAdapter({
|
|
45
39
|
* rootGroup: "@global"
|
|
46
40
|
* }),
|
|
47
|
-
* eventBus,
|
|
48
41
|
* });
|
|
49
42
|
* ```
|
|
50
43
|
*/
|
|
51
44
|
constructor(settings) {
|
|
52
45
|
const { adapter, eventBus: groupdEventBus = new EventBus({
|
|
53
|
-
adapter: new
|
|
46
|
+
adapter: new MemoryEventBusAdapter({
|
|
47
|
+
rootGroup: "@global",
|
|
48
|
+
}),
|
|
54
49
|
}), defaultTtl = null, retryAttempts = null, backoffPolicy = null, retryPolicy = Cache.defaultRetryPolicy, timeout = null, } = settings;
|
|
55
50
|
this.groupdEventBus = groupdEventBus;
|
|
56
51
|
this.eventBus = groupdEventBus.withGroup(adapter.getGroup());
|
|
@@ -69,199 +64,186 @@ export class Cache {
|
|
|
69
64
|
.setTimeout(this.timeout);
|
|
70
65
|
}
|
|
71
66
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
67
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
68
|
+
*
|
|
69
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
70
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
74
71
|
* @example
|
|
75
72
|
* ```ts
|
|
76
73
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
77
74
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
78
75
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
79
76
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
80
|
-
* import {
|
|
81
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
82
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
77
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
83
78
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
84
79
|
*
|
|
85
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
86
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
87
|
-
* });
|
|
88
80
|
* const cache: IGroupableCache = new Cache({
|
|
89
81
|
* adapter: new MemoryCacheAdapter({
|
|
90
82
|
* rootGroup: "@global"
|
|
91
83
|
* }),
|
|
92
|
-
* eventBus,
|
|
93
84
|
* });
|
|
94
85
|
*
|
|
95
|
-
* const listener:
|
|
86
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
96
87
|
* console.log(event);
|
|
97
88
|
* };
|
|
98
89
|
* await cache.addListener(KeyAddedCacheEvent, listener);
|
|
90
|
+
* await cache.add("a", 1);
|
|
99
91
|
* ```
|
|
100
92
|
*/
|
|
101
93
|
addListener(eventName, listener) {
|
|
102
94
|
return this.eventBus.addListener(eventName, listener);
|
|
103
95
|
}
|
|
104
96
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
97
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
98
|
+
*
|
|
99
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
100
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
107
101
|
* @example
|
|
108
102
|
* ```ts
|
|
109
103
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
110
104
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
111
105
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
112
106
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
113
|
-
* import {
|
|
114
|
-
* import type {
|
|
115
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
116
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
107
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
108
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
117
109
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
118
110
|
*
|
|
119
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
120
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
121
|
-
* });
|
|
122
111
|
* const cache: IGroupableCache = new Cache({
|
|
123
112
|
* adapter: new MemoryCacheAdapter({
|
|
124
113
|
* rootGroup: "@global"
|
|
125
114
|
* }),
|
|
126
|
-
* eventBus,
|
|
127
115
|
* });
|
|
128
116
|
*
|
|
129
|
-
* const listener:
|
|
117
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
130
118
|
* console.log(event);
|
|
131
119
|
* };
|
|
132
120
|
* await cache.addListenerMany([KeyAddedCacheEvent], listener);
|
|
121
|
+
* await cache.add("a", 1);
|
|
133
122
|
* ```
|
|
134
123
|
*/
|
|
135
124
|
addListenerMany(eventNames, listener) {
|
|
136
125
|
return this.eventBus.addListenerMany(eventNames, listener);
|
|
137
126
|
}
|
|
138
127
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
128
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
129
|
+
*
|
|
130
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
131
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
141
132
|
* @example
|
|
142
133
|
* ```ts
|
|
143
134
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
144
135
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
145
136
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
146
137
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
147
|
-
* import {
|
|
148
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
149
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
138
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
150
139
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
151
140
|
*
|
|
152
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
153
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
154
|
-
* });
|
|
155
141
|
* const cache: IGroupableCache = new Cache({
|
|
156
142
|
* adapter: new MemoryCacheAdapter({
|
|
157
143
|
* rootGroup: "@global"
|
|
158
144
|
* }),
|
|
159
|
-
* eventBus,
|
|
160
145
|
* });
|
|
161
146
|
*
|
|
162
|
-
* const listener:
|
|
147
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
163
148
|
* console.log(event);
|
|
164
149
|
* };
|
|
150
|
+
* await cache.addListener(KeyAddedCacheEvent, listener);
|
|
165
151
|
* await cache.removeListener(KeyAddedCacheEvent, listener);
|
|
152
|
+
* await cache.add("a", 1);
|
|
166
153
|
* ```
|
|
167
154
|
*/
|
|
168
155
|
removeListener(eventName, listener) {
|
|
169
156
|
return this.eventBus.removeListener(eventName, listener);
|
|
170
157
|
}
|
|
171
158
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
159
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
160
|
+
*
|
|
161
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
162
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
174
163
|
* @example
|
|
175
164
|
* ```ts
|
|
176
165
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
177
166
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
178
167
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
179
168
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
180
|
-
* import {
|
|
181
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
182
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
169
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
183
170
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
184
171
|
*
|
|
185
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
186
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
187
|
-
* });
|
|
188
172
|
* const cache: IGroupableCache = new Cache({
|
|
189
173
|
* adapter: new MemoryCacheAdapter({
|
|
190
174
|
* rootGroup: "@global"
|
|
191
175
|
* }),
|
|
192
|
-
* eventBus,
|
|
193
176
|
* });
|
|
194
177
|
*
|
|
195
|
-
* const listener:
|
|
178
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
196
179
|
* console.log(event);
|
|
197
180
|
* };
|
|
181
|
+
* await cache.addListenerMany([KeyAddedCacheEvent], listener);
|
|
198
182
|
* await cache.removeListenerMany(KeyAddedCacheEvent, listener);
|
|
183
|
+
* await cache.add("a", 1);
|
|
199
184
|
* ```
|
|
200
185
|
*/
|
|
201
186
|
removeListenerMany(eventNames, listener) {
|
|
202
187
|
return this.eventBus.removeListenerMany(eventNames, listener);
|
|
203
188
|
}
|
|
204
189
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
190
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
191
|
+
*
|
|
192
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
193
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
207
194
|
* @example
|
|
208
195
|
* ```ts
|
|
209
196
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
210
197
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
211
198
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
212
199
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
213
|
-
* import {
|
|
214
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
215
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
200
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
216
201
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
217
202
|
*
|
|
218
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
219
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
220
|
-
* });
|
|
221
203
|
* const cache: IGroupableCache = new Cache({
|
|
222
204
|
* adapter: new MemoryCacheAdapter({
|
|
223
205
|
* rootGroup: "@global"
|
|
224
206
|
* }),
|
|
225
|
-
* eventBus,
|
|
226
207
|
* });
|
|
227
208
|
*
|
|
228
|
-
* const listener:
|
|
209
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
229
210
|
* console.log(event);
|
|
230
211
|
* };
|
|
231
212
|
* await cache.listenOnce(KeyAddedCacheEvent, listener);
|
|
213
|
+
* await cache.add("a", 1);
|
|
232
214
|
* ```
|
|
233
215
|
*/
|
|
234
216
|
listenOnce(eventName, listener) {
|
|
235
217
|
return this.eventBus.listenOnce(eventName, listener);
|
|
236
218
|
}
|
|
219
|
+
asPromise(event) {
|
|
220
|
+
return this.eventBus.asPromise(event);
|
|
221
|
+
}
|
|
237
222
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
223
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
224
|
+
*
|
|
225
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
226
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
240
227
|
* @example
|
|
241
228
|
* ```ts
|
|
242
229
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
243
230
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
244
231
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
245
232
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
246
|
-
* import {
|
|
247
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
248
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
233
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
249
234
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
250
235
|
*
|
|
251
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
252
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
253
|
-
* });
|
|
254
236
|
* const cache: IGroupableCache = new Cache({
|
|
255
237
|
* adapter: new MemoryCacheAdapter({
|
|
256
238
|
* rootGroup: "@global"
|
|
257
239
|
* }),
|
|
258
|
-
* eventBus,
|
|
259
240
|
* });
|
|
260
241
|
*
|
|
261
|
-
* const listener:
|
|
242
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
262
243
|
* console.log(event);
|
|
263
244
|
* };
|
|
264
245
|
* const unsubscribe = await cache.subscribe(KeyAddedCacheEvent, listener);
|
|
246
|
+
* await cache.add("a", 1);
|
|
265
247
|
* await unsubscribe();
|
|
266
248
|
* ```
|
|
267
249
|
*/
|
|
@@ -269,33 +251,30 @@ export class Cache {
|
|
|
269
251
|
return this.eventBus.subscribe(eventName, listener);
|
|
270
252
|
}
|
|
271
253
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
254
|
+
* You can listen to different events of <i>Cache</i> class instance.
|
|
255
|
+
*
|
|
256
|
+
* Refer to <i>{@link CacheEvents}</i>, to se all events dispatched by <i>Cache</i> class instance.
|
|
257
|
+
* Refer to <i>{@link IEventListenable}</i> for details on how the method works.
|
|
274
258
|
* @example
|
|
275
259
|
* ```ts
|
|
276
260
|
* import type { IGroupableCache } from "@daiso-tech/core/cache/contracts";
|
|
277
261
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
278
262
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
279
263
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
280
|
-
* import {
|
|
281
|
-
* import type { Listener } from "@daiso-tech/core/event-bus/contracts";
|
|
282
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
264
|
+
* import type { Invokable} from "@daiso-tech/core/event-bus/contracts";
|
|
283
265
|
* import { KeyAddedCacheEvent, type CacheEvents } from "@daiso-tech/core/cache/contracts";
|
|
284
266
|
*
|
|
285
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
286
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
287
|
-
* });
|
|
288
267
|
* const cache: IGroupableCache = new Cache({
|
|
289
268
|
* adapter: new MemoryCacheAdapter({
|
|
290
269
|
* rootGroup: "@global"
|
|
291
270
|
* }),
|
|
292
|
-
* eventBus,
|
|
293
271
|
* });
|
|
294
272
|
*
|
|
295
|
-
* const listener:
|
|
273
|
+
* const listener: Invokable<CacheEvents> = event => {
|
|
296
274
|
* console.log(event);
|
|
297
275
|
* };
|
|
298
276
|
* const unsubscribe = await cache.subscribeMany([KeyAddedCacheEvent], listener);
|
|
277
|
+
* await cache.add("a", 1);
|
|
299
278
|
* await unsubscribe();
|
|
300
279
|
* ```
|
|
301
280
|
*/
|
|
@@ -309,17 +288,11 @@ export class Cache {
|
|
|
309
288
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
310
289
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
311
290
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
312
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
313
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
314
291
|
*
|
|
315
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
316
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
317
|
-
* });
|
|
318
292
|
* const cache: IGroupableCache = new Cache({
|
|
319
293
|
* adapter: new MemoryCacheAdapter({
|
|
320
294
|
* rootGroup: "@global"
|
|
321
295
|
* }),
|
|
322
|
-
* eventBus,
|
|
323
296
|
* });
|
|
324
297
|
*
|
|
325
298
|
* // Will print "@global"
|
|
@@ -333,7 +306,7 @@ export class Cache {
|
|
|
333
306
|
*/
|
|
334
307
|
withGroup(group) {
|
|
335
308
|
return new Cache({
|
|
336
|
-
adapter: this.adapter.withGroup(
|
|
309
|
+
adapter: this.adapter.withGroup(resolveOneOrMoreStr(group)),
|
|
337
310
|
defaultTtl: this.defaultTtl,
|
|
338
311
|
eventBus: this.groupdEventBus,
|
|
339
312
|
retryAttempts: this.retryAttempts,
|
|
@@ -349,17 +322,11 @@ export class Cache {
|
|
|
349
322
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
350
323
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
351
324
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
352
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
353
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
354
325
|
*
|
|
355
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
356
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
357
|
-
* });
|
|
358
326
|
* const cache: IGroupableCache = new Cache({
|
|
359
327
|
* adapter: new MemoryCacheAdapter({
|
|
360
328
|
* rootGroup: "@global"
|
|
361
329
|
* }),
|
|
362
|
-
* eventBus,
|
|
363
330
|
* });
|
|
364
331
|
*
|
|
365
332
|
* // Will print "@global"
|
|
@@ -630,7 +597,7 @@ export class Cache {
|
|
|
630
597
|
}
|
|
631
598
|
existsMany(keys) {
|
|
632
599
|
return this.createLayPromise(async () => {
|
|
633
|
-
if (
|
|
600
|
+
if (keys.length === 0) {
|
|
634
601
|
return {};
|
|
635
602
|
}
|
|
636
603
|
const valuePromises = [];
|
|
@@ -657,7 +624,7 @@ export class Cache {
|
|
|
657
624
|
}
|
|
658
625
|
missingMany(keys) {
|
|
659
626
|
return this.createLayPromise(async () => {
|
|
660
|
-
if (
|
|
627
|
+
if (keys.length === 0) {
|
|
661
628
|
return {};
|
|
662
629
|
}
|
|
663
630
|
const valuePromises = [];
|
|
@@ -678,7 +645,7 @@ export class Cache {
|
|
|
678
645
|
}
|
|
679
646
|
getMany(keys) {
|
|
680
647
|
return this.createLayPromise(async () => {
|
|
681
|
-
if (
|
|
648
|
+
if (keys.length === 0) {
|
|
682
649
|
return {};
|
|
683
650
|
}
|
|
684
651
|
const valuePromises = [];
|
|
@@ -704,17 +671,11 @@ export class Cache {
|
|
|
704
671
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
705
672
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
706
673
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
707
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
708
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
709
674
|
*
|
|
710
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
711
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
712
|
-
* });
|
|
713
675
|
* const cache: IGroupableCache = new Cache({
|
|
714
676
|
* adapter: new MemoryCacheAdapter({
|
|
715
677
|
* rootGroup: "@global"
|
|
716
678
|
* }),
|
|
717
|
-
* eventBus,
|
|
718
679
|
* });
|
|
719
680
|
*
|
|
720
681
|
* const result = await cache.getOr("a", -1);
|
|
@@ -729,17 +690,11 @@ export class Cache {
|
|
|
729
690
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
730
691
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
731
692
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
732
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
733
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
734
693
|
*
|
|
735
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
736
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
737
|
-
* });
|
|
738
694
|
* const cache: IGroupableCache = new Cache({
|
|
739
695
|
* adapter: new MemoryCacheAdapter({
|
|
740
696
|
* rootGroup: "@global"
|
|
741
697
|
* }),
|
|
742
|
-
* eventBus,
|
|
743
698
|
* });
|
|
744
699
|
*
|
|
745
700
|
* const result = await cache.getOr("a", () => -1);
|
|
@@ -754,17 +709,11 @@ export class Cache {
|
|
|
754
709
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
755
710
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
756
711
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
757
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
758
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
759
712
|
*
|
|
760
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
761
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
762
|
-
* });
|
|
763
713
|
* const cache: IGroupableCache = new Cache({
|
|
764
714
|
* adapter: new MemoryCacheAdapter({
|
|
765
715
|
* rootGroup: "@global"
|
|
766
716
|
* }),
|
|
767
|
-
* eventBus,
|
|
768
717
|
* });
|
|
769
718
|
*
|
|
770
719
|
* const result = await cache.getOr("a", async () => -1);
|
|
@@ -779,17 +728,11 @@ export class Cache {
|
|
|
779
728
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
780
729
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
781
730
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
782
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
783
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
784
731
|
*
|
|
785
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
786
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
787
|
-
* });
|
|
788
732
|
* const cache: IGroupableCache = new Cache({
|
|
789
733
|
* adapter: new MemoryCacheAdapter({
|
|
790
734
|
* rootGroup: "@global"
|
|
791
735
|
* }),
|
|
792
|
-
* eventBus,
|
|
793
736
|
* });
|
|
794
737
|
*
|
|
795
738
|
* const result = await cache.getOr("a", new LazyPromise(async () => -1));
|
|
@@ -801,7 +744,7 @@ export class Cache {
|
|
|
801
744
|
return this.createLayPromise(async () => {
|
|
802
745
|
const value = await this.get(key);
|
|
803
746
|
if (value === null) {
|
|
804
|
-
return await
|
|
747
|
+
return await resolveAsyncLazyable(defaultValue);
|
|
805
748
|
}
|
|
806
749
|
return value;
|
|
807
750
|
});
|
|
@@ -813,17 +756,11 @@ export class Cache {
|
|
|
813
756
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
814
757
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
815
758
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
816
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
817
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
818
759
|
*
|
|
819
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
820
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
821
|
-
* });
|
|
822
760
|
* const cache: IGroupableCache = new Cache({
|
|
823
761
|
* adapter: new MemoryCacheAdapter({
|
|
824
762
|
* rootGroup: "@global"
|
|
825
763
|
* }),
|
|
826
|
-
* eventBus,
|
|
827
764
|
* });
|
|
828
765
|
*
|
|
829
766
|
* const result = await cache.getOrMany({ a: -1 });
|
|
@@ -838,17 +775,11 @@ export class Cache {
|
|
|
838
775
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
839
776
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
840
777
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
841
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
842
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
843
778
|
*
|
|
844
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
845
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
846
|
-
* });
|
|
847
779
|
* const cache: IGroupableCache = new Cache({
|
|
848
780
|
* adapter: new MemoryCacheAdapter({
|
|
849
781
|
* rootGroup: "@global"
|
|
850
782
|
* }),
|
|
851
|
-
* eventBus,
|
|
852
783
|
* });
|
|
853
784
|
*
|
|
854
785
|
* const result = await cache.getOrMany({ a: () => -1 });
|
|
@@ -863,17 +794,11 @@ export class Cache {
|
|
|
863
794
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
864
795
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
865
796
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
866
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
867
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
868
797
|
*
|
|
869
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
870
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
871
|
-
* });
|
|
872
798
|
* const cache: IGroupableCache = new Cache({
|
|
873
799
|
* adapter: new MemoryCacheAdapter({
|
|
874
800
|
* rootGroup: "@global"
|
|
875
801
|
* }),
|
|
876
|
-
* eventBus,
|
|
877
802
|
* });
|
|
878
803
|
*
|
|
879
804
|
* const result = await cache.getOrMany({ a: async () => -1 });
|
|
@@ -888,17 +813,11 @@ export class Cache {
|
|
|
888
813
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
889
814
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
890
815
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
891
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
892
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
893
816
|
*
|
|
894
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
895
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
896
|
-
* });
|
|
897
817
|
* const cache: IGroupableCache = new Cache({
|
|
898
818
|
* adapter: new MemoryCacheAdapter({
|
|
899
819
|
* rootGroup: "@global"
|
|
900
820
|
* }),
|
|
901
|
-
* eventBus,
|
|
902
821
|
* });
|
|
903
822
|
*
|
|
904
823
|
* const result = await cache.getOrMany({ a: new LazyPromise(async () => - 1) });
|
|
@@ -909,7 +828,7 @@ export class Cache {
|
|
|
909
828
|
getOrMany(keysWithDefaults) {
|
|
910
829
|
return this.createLayPromise(async () => {
|
|
911
830
|
const keys = Object.keys(keysWithDefaults);
|
|
912
|
-
if (
|
|
831
|
+
if (keys.length === 0) {
|
|
913
832
|
return {};
|
|
914
833
|
}
|
|
915
834
|
const valuePromises = [];
|
|
@@ -936,17 +855,11 @@ export class Cache {
|
|
|
936
855
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
937
856
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
938
857
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
939
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
940
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
941
858
|
*
|
|
942
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
943
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
944
|
-
* });
|
|
945
859
|
* const cache: IGroupableCache = new Cache({
|
|
946
860
|
* adapter: new MemoryCacheAdapter({
|
|
947
861
|
* rootGroup: "@global"
|
|
948
862
|
* }),
|
|
949
|
-
* eventBus,
|
|
950
863
|
* });
|
|
951
864
|
*
|
|
952
865
|
* await cache.add("a", 1);
|
|
@@ -1038,7 +951,7 @@ export class Cache {
|
|
|
1038
951
|
}
|
|
1039
952
|
removeMany(keys) {
|
|
1040
953
|
return this.createLayPromise(async () => {
|
|
1041
|
-
if (
|
|
954
|
+
if (keys.length === 0) {
|
|
1042
955
|
return {};
|
|
1043
956
|
}
|
|
1044
957
|
const valuePromises = [];
|
|
@@ -1064,17 +977,11 @@ export class Cache {
|
|
|
1064
977
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
1065
978
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
1066
979
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
1067
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
1068
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
1069
980
|
*
|
|
1070
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
1071
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1072
|
-
* });
|
|
1073
981
|
* const cache: IGroupableCache = new Cache({
|
|
1074
982
|
* adapter: new MemoryCacheAdapter({
|
|
1075
983
|
* rootGroup: "@global"
|
|
1076
984
|
* }),
|
|
1077
|
-
* eventBus,
|
|
1078
985
|
* });
|
|
1079
986
|
*
|
|
1080
987
|
* const result1 = await cache.getAndRemove("a");
|
|
@@ -1109,17 +1016,11 @@ export class Cache {
|
|
|
1109
1016
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
1110
1017
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
1111
1018
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
1112
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
1113
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
1114
1019
|
*
|
|
1115
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
1116
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1117
|
-
* });
|
|
1118
1020
|
* const cache: IGroupableCache = new Cache({
|
|
1119
1021
|
* adapter: new MemoryCacheAdapter({
|
|
1120
1022
|
* rootGroup: "@global"
|
|
1121
1023
|
* }),
|
|
1122
|
-
* eventBus,
|
|
1123
1024
|
* });
|
|
1124
1025
|
*
|
|
1125
1026
|
* const result = await cache.getOrAdd("a", -1);
|
|
@@ -1134,17 +1035,11 @@ export class Cache {
|
|
|
1134
1035
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
1135
1036
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
1136
1037
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
1137
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
1138
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
1139
1038
|
*
|
|
1140
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
1141
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1142
|
-
* });
|
|
1143
1039
|
* const cache: IGroupableCache = new Cache({
|
|
1144
1040
|
* adapter: new MemoryCacheAdapter({
|
|
1145
1041
|
* rootGroup: "@global"
|
|
1146
1042
|
* }),
|
|
1147
|
-
* eventBus,
|
|
1148
1043
|
* });
|
|
1149
1044
|
*
|
|
1150
1045
|
* const result = await cache.getOrAdd("a", () => -1);
|
|
@@ -1159,17 +1054,11 @@ export class Cache {
|
|
|
1159
1054
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
1160
1055
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
1161
1056
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
1162
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
1163
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
1164
1057
|
*
|
|
1165
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
1166
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1167
|
-
* });
|
|
1168
1058
|
* const cache: IGroupableCache = new Cache({
|
|
1169
1059
|
* adapter: new MemoryCacheAdapter({
|
|
1170
1060
|
* rootGroup: "@global"
|
|
1171
1061
|
* }),
|
|
1172
|
-
* eventBus,
|
|
1173
1062
|
* });
|
|
1174
1063
|
*
|
|
1175
1064
|
* const result = await cache.getOrAdd("a", async () => -1);
|
|
@@ -1184,17 +1073,11 @@ export class Cache {
|
|
|
1184
1073
|
* import type { IGroupableEventBus } from "@daiso-tech/core/event-bus/contracts";
|
|
1185
1074
|
* import { Cache } from "@daiso-tech/core/cache/implementations/derivables";
|
|
1186
1075
|
* import { MemoryCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
|
|
1187
|
-
* import { EventBus } from "@daiso-tech/core/event-bus/implementations/derivables";
|
|
1188
|
-
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/implementations/adapters";
|
|
1189
1076
|
*
|
|
1190
|
-
* const eventBus: IGroupableEventBus = new EventBus({
|
|
1191
|
-
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
1192
|
-
* });
|
|
1193
1077
|
* const cache: IGroupableCache = new Cache({
|
|
1194
1078
|
* adapter: new MemoryCacheAdapter({
|
|
1195
1079
|
* rootGroup: "@global"
|
|
1196
1080
|
* }),
|
|
1197
|
-
* eventBus,
|
|
1198
1081
|
* });
|
|
1199
1082
|
*
|
|
1200
1083
|
* const result = await cache.getOrAdd("a", new LazyPromise(async () => -1));
|
|
@@ -1210,7 +1093,7 @@ export class Cache {
|
|
|
1210
1093
|
return this.createLayPromise(async () => {
|
|
1211
1094
|
const value = await this.get(key);
|
|
1212
1095
|
if (value === null) {
|
|
1213
|
-
const simplifiedValueToAdd = await
|
|
1096
|
+
const simplifiedValueToAdd = await resolveAsyncLazyable(valueToAdd);
|
|
1214
1097
|
await this.add(key, simplifiedValueToAdd, ttl);
|
|
1215
1098
|
return simplifiedValueToAdd;
|
|
1216
1099
|
}
|