
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Memory in Japanese - A powerful and flexible memoization library for TypeScript/JavaScript
Kioku is a comprehensive memoization library that supports synchronous functions, asynchronous functions (Promises), generator functions, and async generator functions. It ships with configurable caching (LRU + TTL) implemented without runtime dependencies and embraces strict TypeScript typing throughout the API surface.
npm install kioku
import { memoize, setup, clearCache, getCacheStats } from 'kioku';
// Basic usage
const expensiveFunction = memoize((a: number, b: number) => {
console.log('Computing...');
return a + b;
});
console.log(expensiveFunction(1, 2)); // Computing... 3
console.log(expensiveFunction(1, 2)); // 3 (cached)
// Configure cache
setup({ max: 1000, ttl: 60000 });
// Get cache statistics
const stats = getCacheStats();
console.log(`Cache size: ${stats.size}/${stats.max}`);
// Clear cache
clearCache();
import { memoize } from 'kioku';
const fibonacci = memoize((n: number): number => {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
});
console.log(fibonacci(40)); // Fast due to memoization
import { memoize } from 'kioku';
const fetchUserData = memoize(async (userId: string) => {
const response = await fetch(`/api/users/${userId}`);
return response.json();
});
// First call fetches data
const user1 = await fetchUserData('123');
// Second call returns cached result
const user2 = await fetchUserData('123');
import { memoize } from 'kioku';
const numberGenerator = memoize(function* (start: number, count: number) {
for (let i = 0; i < count; i++) {
yield start + i;
}
});
const gen1 = numberGenerator(1, 5);
const gen2 = numberGenerator(1, 5); // Returns cached generator
Kioku matches arguments by reference. Reuse the same object when you expect a cache hit, or provide your own lightweight key wrapper if you need structural equality.
import { memoize } from 'kioku';
const processUser = memoize((user: { id: string; name: string }, options: { verbose?: boolean }) => {
console.log(`Processing user: ${user.name}`);
return { processed: true, userId: user.id };
});
const user = { id: '123', name: 'John' };
const options = { verbose: true };
processUser(user, options); // Processing user: John
processUser(user, options); // Cached result (same object references)
// A different object reference counts as a new cache entry
processUser({ id: '123', name: 'John' }, options); // Executes again
memoize<T>(fn: T): TCreates a memoized version of the provided function.
Parameters:
fn: The function to memoize (supports sync, async, generator, and async generator functions)Returns: The memoized function with the same signature as the original
setup(options?: CacheConfig): voidConfigures the global cache settings.
Parameters:
options.max (optional): Maximum number of cache entries (default: 100)options.ttl (optional): Time to live for cache entries in milliseconds (default: 300000)clearCache(): voidClears all entries from the cache.
getCacheStats(): CacheStatsReturns statistics about the current cache state.
Returns:
size: Current number of entries in the cachemax: Maximum number of entries the cache can holdimport { setup } from 'kioku';
// Configure cache with custom settings
setup({
max: 500, // Maximum 500 entries
ttl: 30000 // 30 seconds TTL
});
import { getCacheStats } from 'kioku';
const stats = getCacheStats();
console.log(`Cache utilization: ${stats.size}/${stats.max}`);
console.log(`Usage percentage: ${(stats.size / stats.max * 100).toFixed(1)}%`);
import { clearCache } from 'kioku';
// Clear cache when memory usage is high
if (process.memoryUsage().heapUsed > threshold) {
clearCache();
}
max values for your use case.Kioku works in all modern browsers that support:
Kioku has been optimized for performance and compared against other popular memoization libraries (p-memoize, memoizee, fast-memoize).
| Library | Ops/sec | Relative Performance |
|---|---|---|
| Vanilla JS | 8,852,847.96 | ████████████████████ 100% |
| Kioku | 2,064,162.42 | ██████░░░░░░░░░░░░░░ 23% |
| memoizee | 2,046,211.64 | ██████░░░░░░░░░░░░░░ 23% |
| fast-memoize | 1,439,971.89 | ████░░░░░░░░░░░░░░░░ 16% |
| Library | Ops/sec | Speedup vs Vanilla | Relative Performance |
|---|---|---|---|
| memoizee | 10,656.51 | 12.4x | ████████████████████ 100% |
| p-memoize | 9,782.79 | 11.4x | █████████████████░░░ 92% |
| Kioku | 8,081.35 | 9.4x | ██████████████░░░░░░ 76% |
| Vanilla JS | 859.26 | 1.0x | ███░░░░░░░░░░░░░░░░░ 8% |
| Library | Ops/sec | Cache Effectiveness |
|---|---|---|
| Vanilla JS | 3,306,703.35 | 0% reduction |
| fast-memoize | 2,828,518.25 | 99.0% reduction |
| Kioku | 1,587,616.59 | 99.0% reduction |
| memoizee | 624,089.61 | 99.0% reduction |
See benchmark/RESULTS.md for detailed results.
We welcome contributions! Please see our Contributing Guide for details.
This project adheres to a Code of Conduct. By participating, you are expected to uphold this code.
MIT © Julien Andreu
FAQs
記憶 (ki-o-ku) = MEMORY in Japanese - Memoize functions and cache results
We found that kioku 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.