@aws-sdk/endpoint-cache 3.183.0 → 3.186.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 +8 -0
- package/dist-es/EndpointCache.js +31 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/endpoint-cache
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aws-sdk/endpoint-cache
|
package/dist-es/EndpointCache.js
CHANGED
|
@@ -1,53 +1,58 @@
|
|
|
1
1
|
import LRUCache from "mnemonist/lru-cache";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
var EndpointCache = (function () {
|
|
3
|
+
function EndpointCache(capacity) {
|
|
4
4
|
this.cache = new LRUCache(capacity);
|
|
5
5
|
}
|
|
6
|
-
getEndpoint(key) {
|
|
7
|
-
|
|
6
|
+
EndpointCache.prototype.getEndpoint = function (key) {
|
|
7
|
+
var endpointsWithExpiry = this.get(key);
|
|
8
8
|
if (!endpointsWithExpiry || endpointsWithExpiry.length === 0) {
|
|
9
9
|
return undefined;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
var endpoints = endpointsWithExpiry.map(function (endpoint) { return endpoint.Address; });
|
|
12
12
|
return endpoints[Math.floor(Math.random() * endpoints.length)];
|
|
13
|
-
}
|
|
14
|
-
get(key) {
|
|
13
|
+
};
|
|
14
|
+
EndpointCache.prototype.get = function (key) {
|
|
15
15
|
if (!this.has(key)) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
var value = this.cache.get(key);
|
|
19
19
|
if (!value) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
var now = Date.now();
|
|
23
|
+
var endpointsWithExpiry = value.filter(function (endpoint) { return now < endpoint.Expires; });
|
|
24
24
|
if (endpointsWithExpiry.length === 0) {
|
|
25
25
|
this.delete(key);
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
28
|
return endpointsWithExpiry;
|
|
29
|
-
}
|
|
30
|
-
set(key, endpoints) {
|
|
31
|
-
|
|
32
|
-
this.cache.set(key, endpoints.map((
|
|
33
|
-
Address,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
};
|
|
30
|
+
EndpointCache.prototype.set = function (key, endpoints) {
|
|
31
|
+
var now = Date.now();
|
|
32
|
+
this.cache.set(key, endpoints.map(function (_a) {
|
|
33
|
+
var Address = _a.Address, CachePeriodInMinutes = _a.CachePeriodInMinutes;
|
|
34
|
+
return ({
|
|
35
|
+
Address: Address,
|
|
36
|
+
Expires: now + CachePeriodInMinutes * 60 * 1000,
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
EndpointCache.prototype.delete = function (key) {
|
|
38
41
|
this.cache.set(key, []);
|
|
39
|
-
}
|
|
40
|
-
has(key) {
|
|
42
|
+
};
|
|
43
|
+
EndpointCache.prototype.has = function (key) {
|
|
41
44
|
if (!this.cache.has(key)) {
|
|
42
45
|
return false;
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
var endpoints = this.cache.peek(key);
|
|
45
48
|
if (!endpoints) {
|
|
46
49
|
return false;
|
|
47
50
|
}
|
|
48
51
|
return endpoints.length > 0;
|
|
49
|
-
}
|
|
50
|
-
clear() {
|
|
52
|
+
};
|
|
53
|
+
EndpointCache.prototype.clear = function () {
|
|
51
54
|
this.cache.clear();
|
|
52
|
-
}
|
|
53
|
-
|
|
55
|
+
};
|
|
56
|
+
return EndpointCache;
|
|
57
|
+
}());
|
|
58
|
+
export { EndpointCache };
|