UNPKG

@kilterset/auth0-actions-testing

Version:

Test and develop Auth0 Actions or Okta CIC Actions locally.

38 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cache = cache; // “If no lifetime is specified, a default of lifetime of 15 minutes will be used.” const FIFTEEN_MINS_IN_MS = 15 * 60 * 1000; function cache(values = {}) { const cacheMap = new Map(); const cache = { get: (key) => { const record = cacheMap.get(key); if (record && record.expires_at > Date.now()) { return record.value; } }, set: (key, value, options) => { var _a, _b; const ttl = (_a = options === null || options === void 0 ? void 0 : options.ttl) !== null && _a !== void 0 ? _a : FIFTEEN_MINS_IN_MS; const expires_at = (_b = options === null || options === void 0 ? void 0 : options.expires_at) !== null && _b !== void 0 ? _b : Date.now() + ttl; const record = { value, expires_at }; cacheMap.set(key, record); return { type: "success", record }; }, delete: (key) => { if (cacheMap.delete(key)) { return { type: "success" }; } else { return { type: "error", code: "CacheKeyDoesNotExist", }; } }, }; Object.entries(values).forEach(([key, value]) => cache.set(key, value)); return cache; } //# sourceMappingURL=cache.js.map