初始化环境文件
This commit is contained in:
50
node_modules/@smithy/util-endpoints/dist-es/cache/EndpointCache.js
generated
vendored
Normal file
50
node_modules/@smithy/util-endpoints/dist-es/cache/EndpointCache.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
export class EndpointCache {
|
||||
capacity;
|
||||
data = new Map();
|
||||
parameters = [];
|
||||
constructor({ size, params }) {
|
||||
this.capacity = size ?? 50;
|
||||
if (params) {
|
||||
this.parameters = params;
|
||||
}
|
||||
}
|
||||
get(endpointParams, resolver) {
|
||||
const key = this.hash(endpointParams);
|
||||
if (key === false) {
|
||||
return resolver();
|
||||
}
|
||||
if (!this.data.has(key)) {
|
||||
if (this.data.size > this.capacity + 10) {
|
||||
const keys = this.data.keys();
|
||||
let i = 0;
|
||||
while (true) {
|
||||
const { value, done } = keys.next();
|
||||
this.data.delete(value);
|
||||
if (done || ++i > 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.data.set(key, resolver());
|
||||
}
|
||||
return this.data.get(key);
|
||||
}
|
||||
size() {
|
||||
return this.data.size;
|
||||
}
|
||||
hash(endpointParams) {
|
||||
let buffer = "";
|
||||
const { parameters } = this;
|
||||
if (parameters.length === 0) {
|
||||
return false;
|
||||
}
|
||||
for (const param of parameters) {
|
||||
const val = String(endpointParams[param] ?? "");
|
||||
if (val.includes("|;")) {
|
||||
return false;
|
||||
}
|
||||
buffer += val + "|;";
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user