Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
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
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
// 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
})
Licensed under the MIT License, Copyright 2015 Stefan Penner
FAQs
sync disk cache
The npm package sync-disk-cache receives a total of 319,624 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.