Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
async-disk-cache
Advanced tools
The async-disk-cache npm package is a simple and efficient way to cache data on disk asynchronously. It is useful for scenarios where you need to store and retrieve data quickly without relying on in-memory storage, which can be volatile and limited in size.
Set Cache
This feature allows you to set a cache entry with a specific key and value. The data is stored on disk asynchronously.
const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');
async function setCache(key, value) {
await cache.set(key, value);
console.log(`Cache set for key: ${key}`);
}
setCache('exampleKey', 'exampleValue');
Get Cache
This feature allows you to retrieve a cache entry by its key. It checks if the data is cached and returns the value if it exists.
const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');
async function getCache(key) {
const result = await cache.get(key);
if (result.isCached) {
console.log(`Cache hit for key: ${key}, value: ${result.value}`);
} else {
console.log(`Cache miss for key: ${key}`);
}
}
getCache('exampleKey');
Remove Cache
This feature allows you to remove a cache entry by its key. The data is deleted from the disk asynchronously.
const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');
async function removeCache(key) {
await cache.remove(key);
console.log(`Cache removed for key: ${key}`);
}
removeCache('exampleKey');
Clear Cache
This feature allows you to clear all cache entries. It removes all data stored in the cache asynchronously.
const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');
async function clearCache() {
await cache.clear();
console.log('All cache cleared');
}
clearCache();
node-cache is an in-memory caching module for Node.js. It provides similar functionalities like setting, getting, and deleting cache entries, but it stores data in memory rather than on disk. This makes it faster but less persistent compared to async-disk-cache.
lru-cache is a Least Recently Used (LRU) cache implementation for Node.js. It is designed to store data in memory with a limit on the number of items it can hold. It automatically removes the least recently used items when the limit is reached. Unlike async-disk-cache, it does not persist data on disk.
flat-cache is a lightweight disk-based cache for Node.js. It provides similar functionalities to async-disk-cache, such as setting, getting, and removing cache entries. However, flat-cache is designed to be simpler and more lightweight, making it suitable for smaller projects.
An async disk cache. inspired by jgable/cache-swap
A sync sibling version is also available: stefanpenner/sync-disk-cache
By default, this will usge TMPDIR/<username>/
for storage, but this can be changed by setting the $TMPDIR
environment variable.
var Cache = require('async-disk-cache');
var cache = new Cache('my-cache');
// 'my-cache' also serves as the global key for the cache.
// if you have multiple programs with this same `cache-key` they will share the
// same backing store. This by design.
// checking
cache.has('foo').then(function(wasFooFound) {
});
// retrieving (cache hit)
cache.get('foo').then(function(cacheEntry) {
cacheEntry === {
isCached: true,
key: 'foo',
value: 'content of foo'
}
});
// retrieving (cache miss)
cache.get('foo').then(function(cacheEntry) {
cacheEntry === {
isCached: false,
key: 'foo',
value: undefined
}
});
// setting
cache.set('foo', 'content of foo').then(function() {
// foo was set
});
// clearing one entry from the cache
cache.remove('foo').then(function() {
// foo was removed
})
// clearing the whole cache
cache.clear().then(function() {
// cache was cleared
})
Enable compression:
var Cache = require('async-disk-cache');
var cache = new Cache('my-cache', {
compression: 'gzip' | 'deflate' | 'deflateRaw', // basically just what nodes zlib's ships with
supportBuffer: 'true' | 'false' // add support for file caching (default `false`)
})
In general most OS distributions come with cron like tasks, which purge unused files in $TMPDIR
. For example, ubuntu typically uses tmpreaper
and macOS uses various tasks in /etc/periodic/*
.
If your OS distribution does not provide such a cleanup mechanism:
a) We stronglly recommend utilizing one, as other sync-disk-cache is not alone in rely on this behavior
b) If that is not possible, we recommend changing your $TMPDIR
to something project specific and manually purging it.
Licensed under the MIT License, Copyright 2015 Stefan Penner
FAQs
Async disk cache
The npm package async-disk-cache receives a total of 255,224 weekly downloads. As such, async-disk-cache popularity was classified as popular.
We found that async-disk-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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 malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.