@twin.org/core 0.0.1-next.49 → 0.0.1-next.50
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/cjs/index.cjs
CHANGED
|
@@ -3975,6 +3975,19 @@ class AsyncCache {
|
|
|
3975
3975
|
static async get(key) {
|
|
3976
3976
|
return AsyncCache._cache[key]?.response;
|
|
3977
3977
|
}
|
|
3978
|
+
/**
|
|
3979
|
+
* Set an entry into the cache.
|
|
3980
|
+
* @param key The key to set in the cache.
|
|
3981
|
+
* @param value The value to set in the cache.
|
|
3982
|
+
* @param ttlMs The TTL of the entry in the cache in ms, defaults to 1s.
|
|
3983
|
+
* @returns Nothing.
|
|
3984
|
+
*/
|
|
3985
|
+
static async set(key, value, ttlMs) {
|
|
3986
|
+
AsyncCache._cache[key] = {
|
|
3987
|
+
response: Promise.resolve(value),
|
|
3988
|
+
expires: ttlMs === 0 ? 0 : Date.now() + (ttlMs ?? 1000)
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3978
3991
|
/**
|
|
3979
3992
|
* Remove an entry from the cache.
|
|
3980
3993
|
* @param key The key to remove from the cache.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3973,6 +3973,19 @@ class AsyncCache {
|
|
|
3973
3973
|
static async get(key) {
|
|
3974
3974
|
return AsyncCache._cache[key]?.response;
|
|
3975
3975
|
}
|
|
3976
|
+
/**
|
|
3977
|
+
* Set an entry into the cache.
|
|
3978
|
+
* @param key The key to set in the cache.
|
|
3979
|
+
* @param value The value to set in the cache.
|
|
3980
|
+
* @param ttlMs The TTL of the entry in the cache in ms, defaults to 1s.
|
|
3981
|
+
* @returns Nothing.
|
|
3982
|
+
*/
|
|
3983
|
+
static async set(key, value, ttlMs) {
|
|
3984
|
+
AsyncCache._cache[key] = {
|
|
3985
|
+
response: Promise.resolve(value),
|
|
3986
|
+
expires: ttlMs === 0 ? 0 : Date.now() + (ttlMs ?? 1000)
|
|
3987
|
+
};
|
|
3988
|
+
}
|
|
3976
3989
|
/**
|
|
3977
3990
|
* Remove an entry from the cache.
|
|
3978
3991
|
* @param key The key to remove from the cache.
|
|
@@ -16,6 +16,14 @@ export declare class AsyncCache {
|
|
|
16
16
|
* @returns The item from the cache if it exists.
|
|
17
17
|
*/
|
|
18
18
|
static get<T = unknown>(key: string): Promise<T | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Set an entry into the cache.
|
|
21
|
+
* @param key The key to set in the cache.
|
|
22
|
+
* @param value The value to set in the cache.
|
|
23
|
+
* @param ttlMs The TTL of the entry in the cache in ms, defaults to 1s.
|
|
24
|
+
* @returns Nothing.
|
|
25
|
+
*/
|
|
26
|
+
static set<T = unknown>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
19
27
|
/**
|
|
20
28
|
* Remove an entry from the cache.
|
|
21
29
|
* @param key The key to remove from the cache.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @twin.org/core - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.1-next.50](https://github.com/twinfoundation/framework/compare/core-v0.0.1-next.49...core-v0.0.1-next.50) (2025-03-26)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add set method for async caches ([ba34b55](https://github.com/twinfoundation/framework/commit/ba34b55e651ad56ab8fc59e139e4af631c19cda0))
|
|
9
|
+
|
|
3
10
|
## 0.0.1-next.49
|
|
4
11
|
|
|
5
12
|
- Initial Release
|
|
@@ -78,6 +78,44 @@ The item from the cache if it exists.
|
|
|
78
78
|
|
|
79
79
|
***
|
|
80
80
|
|
|
81
|
+
### set()
|
|
82
|
+
|
|
83
|
+
> `static` **set**\<`T`\>(`key`, `value`, `ttlMs`?): `Promise`\<`void`\>
|
|
84
|
+
|
|
85
|
+
Set an entry into the cache.
|
|
86
|
+
|
|
87
|
+
#### Type Parameters
|
|
88
|
+
|
|
89
|
+
• **T** = `unknown`
|
|
90
|
+
|
|
91
|
+
#### Parameters
|
|
92
|
+
|
|
93
|
+
##### key
|
|
94
|
+
|
|
95
|
+
`string`
|
|
96
|
+
|
|
97
|
+
The key to set in the cache.
|
|
98
|
+
|
|
99
|
+
##### value
|
|
100
|
+
|
|
101
|
+
`T`
|
|
102
|
+
|
|
103
|
+
The value to set in the cache.
|
|
104
|
+
|
|
105
|
+
##### ttlMs?
|
|
106
|
+
|
|
107
|
+
`number`
|
|
108
|
+
|
|
109
|
+
The TTL of the entry in the cache in ms, defaults to 1s.
|
|
110
|
+
|
|
111
|
+
#### Returns
|
|
112
|
+
|
|
113
|
+
`Promise`\<`void`\>
|
|
114
|
+
|
|
115
|
+
Nothing.
|
|
116
|
+
|
|
117
|
+
***
|
|
118
|
+
|
|
81
119
|
### remove()
|
|
82
120
|
|
|
83
121
|
> `static` **remove**(`key`): `void`
|