Static
batchStatic
batchStores multiple key-value pairs in the cache in parallel.
Static
createCreates a memoizer function bound to a specific cache instance. Useful for creating multiple memoized functions with the same cache and default options.
A memoizer function
Static
generateGenerates a hash-based cache key from input data. Uses SHA256 for collision resistance and security.
String or object to generate a key from
A promise that resolves to a SHA256 hash string suitable for use as a cache key
Static
generateStatic
isStatic
memoizeMemoizes a function using the provided cache instance. Creates a cached version of the function that stores results and returns cached values for repeated calls.
A memoized version of the function
const cache = new MemoryCache();
const memoizedFn = CacheUtils.memoize(expensiveFunction, cache, {
ttl: 300000, // 5 minutes
namespace: 'calculations',
keyGenerator: (args) => `custom:${args[0]}`
});
// First call - executes function and caches result
const result1 = await memoizedFn(123);
// Second call - returns cached result
const result2 = await memoizedFn(123);
Static
memoize2Improved memoize function that properly handles both sync and async functions. For async functions, it caches the resolved value, not the promise itself. For sync functions, it caches the return value directly.
A memoized version of the function
Utility functions for common cache operations and key generation.