@ti-engine/core 1.12.3 → 1.13.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/CHANGELOG.md +7 -0
- package/bin/settings.json +1 -0
- package/components/cache/cache-capability.js +42 -0
- package/components/cache/cache-provider.js +432 -0
- package/components/cache/redis-cache-provider.js +749 -0
- package/package.json +13 -1
- package/types/components/cache/cache-capability.d.ts +23 -0
- package/types/components/cache/cache-provider.d.ts +326 -0
- package/types/components/cache/redis-cache-provider.d.ts +327 -0
- package/types/utils/cache.d.ts +40 -32
- package/types/utils/config.d.ts +1 -0
- package/utils/cache.js +126 -388
- package/utils/config.js +7 -0
package/types/utils/cache.d.ts
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
declare const _exported: Readonly<CommonMemoryCache>;
|
|
2
2
|
export { _exported as instance };
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export declare var decodeCommandValue: typeof import("#redis-cache-provider").decodeCommandValue;
|
|
4
|
+
export declare var mapCommandValues: typeof import("#redis-cache-provider").mapCommandValues;
|
|
5
|
+
export { cacheCapability };
|
|
6
|
+
export { findMissingCapabilities };
|
|
5
7
|
import ConnectionObserver = require("#connection-observer");
|
|
8
|
+
import RedisCacheProvider = require("#redis-cache-provider");
|
|
9
|
+
import { cacheCapability } from "#cache-capability";
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* Determines which of the required capabilities a backend does not provide.
|
|
8
12
|
* <br/>
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* This lives outside the class, and is shared by {@link CommonMemoryCache#getValue} and
|
|
13
|
-
* {@link CommonMemoryCache#getValues}, because it previously existed as two near-identical inline expressions and one
|
|
14
|
-
* of them drifted: `getValues` inspected its own accumulator instead of the per-key entry, so `.length` was
|
|
15
|
-
* `undefined`, the comparison was always false, and **every key resolved to `null`** whatever Redis returned.
|
|
13
|
+
* NOTE: This lives outside the class, and is exported, for the same reason the Redis decoders are: the cache singleton
|
|
14
|
+
* builds its own backend in its constructor, so the reconciliation cannot be driven without a live server. This is the
|
|
15
|
+
* pure half of it, and it is the half that decides whether an instance starts.
|
|
16
16
|
*
|
|
17
17
|
* @method
|
|
18
|
-
* @param {
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
|
|
22
|
-
declare function decodeCommandValue(result?: any[]): any;
|
|
23
|
-
/**
|
|
24
|
-
* Maps a set of requested keys onto the values a `multi(...).exec()` returned for them, using `null` for a miss.
|
|
25
|
-
* <br/>
|
|
26
|
-
* Iterates the requested `keys` rather than the raw results, so a short or absent response still yields one entry per
|
|
27
|
-
* requested key instead of silently omitting some — the caller's map always has the shape it asked for.
|
|
28
|
-
* <br/>
|
|
29
|
-
* The accumulator has no prototype on purpose: the key names come from the caller, and a cache key named `__proto__`
|
|
30
|
-
* written by bracket assignment onto an ordinary `{}` would repoint the accumulator's prototype instead of creating
|
|
31
|
-
* the entry. Same class as the `decycle` defect fixed in `tools.js`; see the 1.11.0 changelog entry.
|
|
32
|
-
*
|
|
33
|
-
* @method
|
|
34
|
-
* @param {string[]} keys The keys that were requested, in command order.
|
|
35
|
-
* @param {Array} [rawResults] The `multi(...).exec()` result.
|
|
36
|
-
* @returns {Object} A null-prototype map of key to value, `null` where the key was absent.
|
|
37
|
-
* @private
|
|
18
|
+
* @param {string[]} [required] Capabilities the application declared it needs.
|
|
19
|
+
* @param {string[]} [available] Capabilities the backend reports it provides.
|
|
20
|
+
* @returns {string[]} The required capabilities that are absent, in the order they were required.
|
|
21
|
+
* @public
|
|
38
22
|
*/
|
|
39
|
-
declare function
|
|
23
|
+
declare function findMissingCapabilities(required?: string[], available?: string[]): string[];
|
|
40
24
|
/**
|
|
41
25
|
* Used to create and/or return a Common Memory Cache singleton instance.
|
|
26
|
+
* <br/>
|
|
27
|
+
* NOTE: This owns the cache's operational state and the connection observation around it; where the values actually
|
|
28
|
+
* live is the {@link CacheProvider}'s business. Every method here checks that the cache is usable and then delegates,
|
|
29
|
+
* which is why no provider repeats that check.
|
|
42
30
|
*
|
|
43
31
|
* @class CommonMemoryCache
|
|
44
32
|
* @extends ConnectionObserver
|
|
@@ -68,11 +56,31 @@ declare class CommonMemoryCache extends ConnectionObserver {
|
|
|
68
56
|
* @public
|
|
69
57
|
*/
|
|
70
58
|
get connectionIdentifier(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Property returning the optional behaviors the configured backend provides.
|
|
61
|
+
* <br/>
|
|
62
|
+
* NOTE: Accurate only once {@link CommonMemoryCache#initialize} has resolved — some capabilities cannot be
|
|
63
|
+
* established until the backend has connected.
|
|
64
|
+
*
|
|
65
|
+
* @property
|
|
66
|
+
* @returns {string[]} Values drawn from {@link TiCacheCapability}.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
get capabilities(): string[];
|
|
71
70
|
/**
|
|
72
71
|
* Used to initialize the cache service.
|
|
72
|
+
* <br/>
|
|
73
|
+
* NOTE: Once the backend is connected, the capabilities it reports are reconciled against the
|
|
74
|
+
* 'memoryCache.requiredCapabilities' setting, and startup fails if any of them is missing. That is deliberate: a
|
|
75
|
+
* backend silently lacking a behavior the application depends on is otherwise discovered from inside a request,
|
|
76
|
+
* long after the deployment that introduced it.
|
|
77
|
+
* <br/>
|
|
78
|
+
* NOTE: A failed reconciliation rolls the cache back to non-operational and shuts the backend down before it
|
|
79
|
+
* rejects, so a refused startup never leaves a usable cache behind.
|
|
73
80
|
*
|
|
74
81
|
* @method
|
|
75
82
|
* @returns {Promise}
|
|
83
|
+
* @throws {TiException.E_GEN_FEATURE_UNSUPPORTED} If the backend does not provide every required capability.
|
|
76
84
|
* @public
|
|
77
85
|
*/
|
|
78
86
|
initialize(): Promise<any>;
|
|
@@ -113,7 +121,7 @@ declare class CommonMemoryCache extends ConnectionObserver {
|
|
|
113
121
|
*/
|
|
114
122
|
onConnectionLost(identifier: string): void;
|
|
115
123
|
/**
|
|
116
|
-
* Used to register a new {@link ConnectionObserver} for events related to the underlying
|
|
124
|
+
* Used to register a new {@link ConnectionObserver} for events related to the underlying backend connection state.
|
|
117
125
|
*
|
|
118
126
|
* @method
|
|
119
127
|
* @param {ConnectionObserver} connectionObserver The {@link ConnectionObserver} that will be notified of any changes.
|
package/types/utils/config.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare const settingsEnum: import("../components/definitions.types").TiEnumOf<{
|
|
|
21
21
|
MEMORY_CACHE_REDIS_DB: string[];
|
|
22
22
|
MEMORY_CACHE_REDIS_HOST: string[];
|
|
23
23
|
MEMORY_CACHE_REDIS_PORT: string[];
|
|
24
|
+
MEMORY_CACHE_REQUIRED_CAPABILITIES: string[];
|
|
24
25
|
MEMORY_CACHE_RETRY_MAX_ATTEMPTS: string[];
|
|
25
26
|
MEMORY_CACHE_RETRY_MAX_INTERVAL: string[];
|
|
26
27
|
MEMORY_CACHE_USER: string[];
|