Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@hapi/catbox-memory
Advanced tools
@hapi/catbox-memory is a memory-based caching module for the hapi.js framework. It provides a simple and efficient way to store and retrieve data in memory, making it useful for scenarios where quick access to cached data is required.
Basic Caching
This code demonstrates how to set up a basic in-memory cache using @hapi/catbox-memory. It initializes a Catbox client with the memory engine, sets a value in the cache, and retrieves it.
const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');
const client = new Catbox.Client(CatboxMemory);
const start = async () => {
await client.start();
const key = { id: 'example', segment: 'examples' };
await client.set(key, 'my cached value', 10000); // Cache for 10 seconds
const cached = await client.get(key);
console.log(cached.item); // Outputs: 'my cached value'
};
start();
Cache Expiration
This code demonstrates how to set a cache expiration time. The cached value will expire after 5 seconds, and attempting to retrieve it after 6 seconds will return null.
const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');
const client = new Catbox.Client(CatboxMemory);
const start = async () => {
await client.start();
const key = { id: 'example', segment: 'examples' };
await client.set(key, 'my cached value', 5000); // Cache for 5 seconds
setTimeout(async () => {
const cached = await client.get(key);
console.log(cached); // Outputs: null (cache expired)
}, 6000);
};
start();
Cache Deletion
This code demonstrates how to delete a cache entry. After setting a value in the cache, it is deleted using the drop method, and subsequent retrieval returns null.
const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');
const client = new Catbox.Client(CatboxMemory);
const start = async () => {
await client.start();
const key = { id: 'example', segment: 'examples' };
await client.set(key, 'my cached value', 10000); // Cache for 10 seconds
await client.drop(key); // Delete the cache entry
const cached = await client.get(key);
console.log(cached); // Outputs: null (cache deleted)
};
start();
node-cache is a simple and efficient in-memory caching module for Node.js. It provides similar functionality to @hapi/catbox-memory, including setting, getting, and deleting cache entries with expiration times. However, node-cache is a standalone module and does not require the hapi.js framework.
memory-cache is another in-memory caching module for Node.js. It offers basic caching functionalities such as setting, getting, and deleting cache entries with expiration times. Like node-cache, it is a standalone module and does not depend on any specific framework.
lru-cache is a caching module that implements a Least Recently Used (LRU) cache algorithm. It provides more advanced caching strategies compared to @hapi/catbox-memory, making it suitable for scenarios where memory usage needs to be optimized by evicting the least recently used items.
Memory adapter for catbox. This adapter is not designed to share a common cache between multiple processes (e.g. in a cluster mode). It uses a single interval timeout to look for expired records and clean them from memory.
maxByteSize
- sets an upper limit on the number of bytes that can be stored in the
cache. Once this limit is reached no additional items will be added to the cache
until some expire. The utilized memory calculation is a rough approximation and must
not be relied on. Defaults to 104857600
(100MB).minCleanupIntervalMsec
- the minimum number of milliseconds in between each cache cleanup.
Defaults to 1 second (1000
).cloneBuffersOnGet
- by default, buffers stored in the cache are copied when they are set but
not when they are retrieved. This means a change to the buffer returned by a get()
will change
the value in the cache. To prevent this, set cloneBuffersOnGet
to true
to always return a
copy of the cached buffer. Defaults to false
.FAQs
Memory adapter for catbox
The npm package @hapi/catbox-memory receives a total of 687,417 weekly downloads. As such, @hapi/catbox-memory popularity was classified as popular.
We found that @hapi/catbox-memory demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.