Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
file-system-cache
Advanced tools
A super-fast, promise-based cache that reads and writes to the file-system.
The file-system-cache npm package provides a simple and efficient way to cache data on the file system. It allows you to store, retrieve, and manage cached data, making it useful for applications that need to cache data locally to improve performance and reduce redundant operations.
Set Cache
This feature allows you to set a value in the cache with a specific key. The code sample demonstrates how to set a cache entry with the key 'key' and the value 'value'.
const FileSystemCache = require('file-system-cache');
const cache = FileSystemCache.default();
cache.set('key', 'value').then(() => {
console.log('Cache set successfully');
});
Get Cache
This feature allows you to retrieve a value from the cache using a specific key. The code sample demonstrates how to get the cached value for the key 'key'.
const FileSystemCache = require('file-system-cache');
const cache = FileSystemCache.default();
cache.get('key').then(value => {
console.log('Cached value:', value);
});
Remove Cache
This feature allows you to remove a specific entry from the cache using its key. The code sample demonstrates how to remove the cache entry for the key 'key'.
const FileSystemCache = require('file-system-cache');
const cache = FileSystemCache.default();
cache.remove('key').then(() => {
console.log('Cache removed successfully');
});
Clear Cache
This feature allows you to clear all entries from the cache. The code sample demonstrates how to clear the entire cache.
const FileSystemCache = require('file-system-cache');
const cache = FileSystemCache.default();
cache.clear().then(() => {
console.log('Cache cleared successfully');
});
node-cache is an in-memory caching module for Node.js. It provides similar functionalities to file-system-cache but stores data in memory instead of the file system. This makes it faster for read/write operations but less persistent across application restarts.
cache-manager is a multi-level caching module for Node.js that supports various storage engines, including memory, Redis, and file system. It offers more flexibility and scalability compared to file-system-cache, making it suitable for more complex caching needs.
flat-cache is a lightweight and fast cache for Node.js that stores data in a flat file. It is similar to file-system-cache in terms of file-based storage but is designed to be simpler and more efficient for small to medium-sized caches.
A super-fast, promise-based cache that reads and writes to the file-system.
npm install --save file-system-cache
Create an instance of the cache optionally giving it a folder location to store files within.
import Cache from "file-system-cache";
const cache = Cache({
basePath: "./.cache", // Optional. Path where cache files are stored (default).
ns: "my-namespace" // Optional. A grouping namespace for items.
});
Reference
default
for CommonJS, e.g:const Cache = require('file-system-cache').default
The optional ns
("namespace") allows for multiple groupings of files to reside within the one cache folder. When you have multiple caches with different namespaces you can re-use the same keys and they will not collide.
Retrieves the contents of a cached file.
cache.get("foo")
.then(result => /* Success */)
.catch(err => /* Fail */);
Use getSync
for a synchronous version. Pass a defaultValue
parameter to have that value returned if nothing exists within the cache.
Write a value to the cache.
cache.set("foo", "...value...")
.then(result => /* Success */)
Value types are stored and respected on subsequent calls to get
. For examples, passing in Object will return that in its parsed object state.
Use setSync
for a synchronous version.
Deletes the specified cache item from the file-system.
cache.remove("foo")
.then(() => /* Removed */)
Clears all cached items from the file-system.
cache.clear()
.then(() => /* All items deleted */)
Saves (sets) several items to the cache in one operation.
cache.save([{ key:"one", value:"hello" }, { key:"two", value:222 }])
.then(result => /* All items saved. */)
Loads all files within the cache's namespace.
cache.load()
.then(result => /* The complete of cached files (for the ns). */)
# Run tests.
npm test
# Watch and re-run tests.
npm run tdd
FAQs
A super-fast, promise-based cache that reads and writes to the file-system.
We found that file-system-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.