UNPKG

@aws-lambda-powertools/parameters

Version:
33 lines (32 loc) 895 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExpirableValue = void 0; /** * Class to represent a value that can expire. * * Upon creation, the value is assigned a TTL (time to live) that is calculated * by adding the current time with the maximum age. */ class ExpirableValue { ttl; value; /** * * @param value - Value to be cached * @param maxAge - Maximum age in seconds for the value to be cached */ constructor(value, maxAge) { this.value = value; const timeNow = new Date(); this.ttl = timeNow.setSeconds(timeNow.getSeconds() + maxAge); } /** * Check if the value has expired. * * @returns {boolean} - True if the value has expired, false otherwise */ isExpired() { return this.ttl < Date.now(); } } exports.ExpirableValue = ExpirableValue;