![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
file-system-cache
Advanced tools
Changelog
[2.3.0] - 2023-05-22
ttl
(time to live) to expire caches (thanks @douglaslinsmeyer)Readme
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.
ttl: 60 // Optional. A time-to-live that determines how long the cache item is valid, in seconds.
});
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.
The optional ttl
("time to live") allows you to set a default expiration for the cache key, in seconds. For example if you
set this value to 60 then cache hits to any cache key made beyond the limit of that 60 seconds will result in cache misses.
Retrieves the contents of a cached file.
cache.get("foo")
.then(result => /* Success */)
.catch(err => /* Fail */);
or use modern async/await
syntactic sugar of course:
const value = await cache.get("foo");
Use getSync
for a synchronous version.
Pass a defaultValue
parameter to use if the key does not exist within the cache.
Write a value to the cache.
/* This will apply the default TTL to this cache key */
cache.set("foo", "...value...")
.then(result => /* Success */)
/* This will set a specific TTL for this cache key */
cache.set("bar", "...baz", 60)
.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
FAQs
A super-fast, promise-based cache that reads and writes to the file-system.
The npm package file-system-cache receives a total of 4,701,546 weekly downloads. As such, file-system-cache popularity was classified as popular.
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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.