Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
sync-disk-cache
Advanced tools
The sync-disk-cache npm package provides a simple, synchronous API for caching data to disk. It is useful for scenarios where you need to store and retrieve data quickly without the overhead of asynchronous operations.
Set Cache
This feature allows you to set a key-value pair in the cache. The data is stored on disk and can be retrieved later.
const Cache = require('sync-disk-cache');
const cache = new Cache('myCache');
cache.set('key', 'value');
Get Cache
This feature allows you to retrieve a value from the cache using its key. If the key exists, the value is returned; otherwise, it returns null.
const Cache = require('sync-disk-cache');
const cache = new Cache('myCache');
const result = cache.get('key');
console.log(result.value);
Remove Cache
This feature allows you to remove a key-value pair from the cache. The specified key and its associated value are deleted from the disk.
const Cache = require('sync-disk-cache');
const cache = new Cache('myCache');
cache.remove('key');
Clear Cache
This feature allows you to clear all key-value pairs from the cache. The entire cache is emptied, removing all stored data from the disk.
const Cache = require('sync-disk-cache');
const cache = new Cache('myCache');
cache.clear();
node-cache is an in-memory caching module for Node.js. Unlike sync-disk-cache, it does not persist data to disk, making it faster for read/write operations but less suitable for long-term storage.
flat-cache is a lightweight disk-based cache for Node.js. It provides similar functionality to sync-disk-cache but includes additional features like automatic cache invalidation based on time-to-live (TTL) settings.
diskcache is another disk-based caching solution for Node.js. It offers both synchronous and asynchronous APIs, providing more flexibility compared to sync-disk-cache, which only offers synchronous operations.
A sync disk cache. inspired by jgable/cache-swap
An async sibling version is also available: stefanpenner/async-disk-cache
By default, this will usge TMPDIR/<username>/
for storage, but this can be changed by setting the $TMPDIR
environment variable.
All stored values become strings.
var Cache = require('sync-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') === wasFooFound;
// retrieving (cache hit)
cache.get('foo') === {
isCached: true,
path: 'foo',
content: 'content of foo'
}
// retrieving (cache miss)
cache.get('foo') === {
isCached: false,
path: 'foo',
content: undefined
}
// retrieving (cache miss)
cache.set('foo', 'content of foo'); // was set
// remove a key
cache.remove('foo');
// clearing the cache
cache.clear(); // cache was cleared
Enable compression:
note: node 0.10.x does not support the synchronous zlib method variants, so compression is only available > 0.10.x
var Cache = require('sync-disk-cache');
var cache = new Cache('my-cache', {
compression: 'gzip' | 'deflate' | 'deflateRaw' // basically just what nodes zlib's ships with
})
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
sync disk cache
The npm package sync-disk-cache receives a total of 244,919 weekly downloads. As such, sync-disk-cache popularity was classified as popular.
We found that sync-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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.