
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.
multi-layers-cache
Advanced tools
A very simple multi layers cache.

import { newCacheStorage, newLRUCache } from 'multi-layers-cache';
const cache = newCacheStorage({ layers: [newLRUCache()] });
await cache.set('ah', 10);
console.log(await cache.get('ah'));
newLRUCache will create a simple in-memory LRU cache using Map.
You can build your own cache, with just simple interfaces:
interface Cache {
get(key: string): Promise<Value | undefined>;
/**
* @param expireAt In seconds
*/
set(key: string, value: string | number, expireAt?: number): Promise<void>;
del(key: string): Promise<void>;
}
interface Value {
expireAt: number;
value: string | number;
key: string;
}
import { Redis } from 'ioredis'
interface Cache {
get(key: string): Promise<Value | undefined>
/**
* @param expireAt In seconds
*/
set(key: string, value: string | number, expireAt?: number): Promise<void>
del(key: string): Promise<void>
}
interface Value {
/**
* `-1` means No expiration.
*/
expireAt: number
value: string | number
key: string
}
export function newRedisCache(): Cache {
const redis = new Redis()
return {
async get(key) {
const results = await redis.pipeline().get(key).ttl(key).exec()
if (!results) {
return
}
const [[, value], [, ttl]] = results
return {
value: value as string,
key,
expireAt: ttl as number,
}
},
async set(key, value, expireAt) {
expireAt ? await redis.setex(key, expireAt, value) : await redis.set(key, value)
},
async del(key) {
await redis.del(key)
},
}
}
import { newCacheStorage, newLRUCache } from 'multi-layers-cache';
const cache = newCacheStorage({ layers: [newLRUCache(), newRedisCache()] });
await cache.set('ah', 'hello', 10 /* 10 seconds */);
console.log(await cache.get('ah'));
newCacheStorage returns a Cache compatible instance.
It maintains an internal array of cache layers. When a get operation is performed, it loops through the cache layers sequentially. If it finds a value on a higher layer, it saves that value to the lower layers with the same ttl. For set and del operations, items are modified or removed in all layers.
BSD-3-Clause @ Ninh Pham (ReeganExE)
FAQs
A very simple multi layers cache.
The npm package multi-layers-cache receives a total of 0 weekly downloads. As such, multi-layers-cache popularity was classified as not popular.
We found that multi-layers-cache demonstrated a not healthy version release cadence and project activity because the last version was released 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.