@aws-sdk/endpoint-cache
Advanced tools
Comparing version 3.183.0 to 3.186.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06) | ||
**Note:** Version bump only for package @aws-sdk/endpoint-cache | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
@@ -8,0 +16,0 @@ |
import LRUCache from "mnemonist/lru-cache"; | ||
export class EndpointCache { | ||
constructor(capacity) { | ||
var EndpointCache = (function () { | ||
function EndpointCache(capacity) { | ||
this.cache = new LRUCache(capacity); | ||
} | ||
getEndpoint(key) { | ||
const endpointsWithExpiry = this.get(key); | ||
EndpointCache.prototype.getEndpoint = function (key) { | ||
var endpointsWithExpiry = this.get(key); | ||
if (!endpointsWithExpiry || endpointsWithExpiry.length === 0) { | ||
return undefined; | ||
} | ||
const endpoints = endpointsWithExpiry.map((endpoint) => endpoint.Address); | ||
var endpoints = endpointsWithExpiry.map(function (endpoint) { return endpoint.Address; }); | ||
return endpoints[Math.floor(Math.random() * endpoints.length)]; | ||
} | ||
get(key) { | ||
}; | ||
EndpointCache.prototype.get = function (key) { | ||
if (!this.has(key)) { | ||
return; | ||
} | ||
const value = this.cache.get(key); | ||
var value = this.cache.get(key); | ||
if (!value) { | ||
return; | ||
} | ||
const now = Date.now(); | ||
const endpointsWithExpiry = value.filter((endpoint) => now < endpoint.Expires); | ||
var now = Date.now(); | ||
var endpointsWithExpiry = value.filter(function (endpoint) { return now < endpoint.Expires; }); | ||
if (endpointsWithExpiry.length === 0) { | ||
@@ -29,18 +29,21 @@ this.delete(key); | ||
return endpointsWithExpiry; | ||
} | ||
set(key, endpoints) { | ||
const now = Date.now(); | ||
this.cache.set(key, endpoints.map(({ Address, CachePeriodInMinutes }) => ({ | ||
Address, | ||
Expires: now + CachePeriodInMinutes * 60 * 1000, | ||
}))); | ||
} | ||
delete(key) { | ||
}; | ||
EndpointCache.prototype.set = function (key, endpoints) { | ||
var now = Date.now(); | ||
this.cache.set(key, endpoints.map(function (_a) { | ||
var Address = _a.Address, CachePeriodInMinutes = _a.CachePeriodInMinutes; | ||
return ({ | ||
Address: Address, | ||
Expires: now + CachePeriodInMinutes * 60 * 1000, | ||
}); | ||
})); | ||
}; | ||
EndpointCache.prototype.delete = function (key) { | ||
this.cache.set(key, []); | ||
} | ||
has(key) { | ||
}; | ||
EndpointCache.prototype.has = function (key) { | ||
if (!this.cache.has(key)) { | ||
return false; | ||
} | ||
const endpoints = this.cache.peek(key); | ||
var endpoints = this.cache.peek(key); | ||
if (!endpoints) { | ||
@@ -50,6 +53,8 @@ return false; | ||
return endpoints.length > 0; | ||
} | ||
clear() { | ||
}; | ||
EndpointCache.prototype.clear = function () { | ||
this.cache.clear(); | ||
} | ||
} | ||
}; | ||
return EndpointCache; | ||
}()); | ||
export { EndpointCache }; |
{ | ||
"name": "@aws-sdk/endpoint-cache", | ||
"version": "3.183.0", | ||
"version": "3.186.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24722
208