UNPKG

execution-engine

Version:

A TypeScript library for tracing and visualizing code execution workflows.

42 lines (41 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MapCacheStore = void 0; class MapCacheStore { constructor(fullStorage, functionId) { this.fullStorage = fullStorage; this.functionId = functionId; } /** * Retrieves the value associated with the specified key. * * @param key - The key used to retrieve the value. * @returns The value corresponding to the key. */ get(key) { this.fullStorage ??= new Map(); if (!this.fullStorage.has(this.functionId)) { this.fullStorage.set(this.functionId, new Map()); } this.store = this.fullStorage.get(this.functionId); return this.store.get(key); } /** * Sets a value for the specified key. * * @param key - The key for the value. * @param value - The value to store. * @param ttl - Time to live in milliseconds (optional). * @returns The value that was set. */ set(key, value, ttl) { setTimeout(() => { this.store.delete(key); this.fullStorage.set(this.functionId, this.store); }, ttl); this.store.set(key, value); this.fullStorage.set(this.functionId, this.store); return value; } } exports.MapCacheStore = MapCacheStore;