
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@axync/memorize
Advanced tools

The @axync/memorize package provides a utility function to cache (or "memorize") the results of expensive or frequently called functions. It allows for flexible configuration of cache behavior, including setting a time-to-live (TTL) for cached results and limiting the cache size.
Install the package using npm:
npm install @axync/memorize
The memorize function wraps a given function with a caching layer that stores the results of function calls. This can be particularly useful for optimizing functions that are expensive to execute.
import { memorize } from '@axync/memorize';
async function expensiveOperation(arg: number): Promise<number> {
// Simulate an expensive operation
return new Promise(resolve => setTimeout(() => resolve(arg * 2), 1000));
}
const [memorizedOperation, memoryControl] = memorize(expensiveOperation, {
ttl: 5000, // Cache results for 5 seconds
maxCacheSize: 3, // Only keep the 3 most recent results
});
const result = await memorizedOperation('key1', 5);
console.log(result); // Outputs: 10 (after 1 second)
const cachedResult = await memorizedOperation('key1', 5);
console.log(cachedResult); // Outputs: 10 (almost instantly)
The MemorizeOptions interface allows you to configure how the caching works:
ttl: The time-to-live (in milliseconds) for cached results. After this time, cached results will be considered expired and will not be returned.maxCacheSize: The maximum number of results to store in the cache. If this limit is reached, the oldest cached result will be removed.When you use the memorize function, it returns a tuple that includes not only the memorized function but also a set of control functions to manage the cache.
importMemory(memoryToImport): Imports a memory object into the current cache.exportMemory(): Exports the current memory object.clearMemory(): Clears all cached results.const [memorizedOperation, memoryControl] = memorize(expensiveOperation);
// Exporting the current cache
const currentMemory = memoryControl.exportMemory();
// Clearing the cache
memoryControl.clearMemory();
// Importing previously exported memory
memoryControl.importMemory(currentMemory);
memorizeUsage: memorize<FunctionType>(fn: FunctionType, options?: MemorizeOptions): [MemorizedFunction<FunctionType>, MemoryControlFunctions<FunctionType>]
fn: The function to be memorized.options: Optional settings for cache behavior, including ttl and maxCacheSize.Returns: A tuple containing:
MemorizedFunction<FunctionType>: The memorized function that can be called with a cache key and arguments.MemoryControlFunctions<FunctionType>: An object with functions to manage the cache (importMemory, exportMemory, and clearMemory).This package is licensed under the MIT License.
FAQs

We found that @axync/memorize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.