Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.