Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
feather-cache
Advanced tools
A Simple Lightweight Pluggable Key-Value Cache For Multiple Storage Options.
A Simple Pluggable Key-Value Cache For Multiple Storage Options.
npm i --save feather-cache
You don't have to install type definitions for typescript. It's built in.
This is a simple caching frame which can be used with available drivers or you can easily write one your own. If no drivers are provided (default) works like an in-memory cache. But that is not what this module intended for. The in-memory cache is provided for the sake of convenience. If that is what all you want, lru-cache is recommended.
Actual use case for this module is to use with a driver (mongodb-driver or indexed-db-driver etc.) which enables persistent caching.
const { FeatherCache } = require('feather-cache');
// or
import { FeatherCache } from 'feather-cache';
// init
const fStore = new FeatherCache({
maxAgeInMs: 60 * 1000, // 1 min expiry
});
// ...async fn...
await fStore.set('hiya', 'mm!');
await fStore.get('hiya'); //-> mm!
await fStore.fetch('hiya'); //-> { key: 'hiya', val: 'mm!' }
// ... after expiry time
await fStore.get('hiya'); //-> null
// ...
const fStore = new FeatherCache(driver);
// ...
function | description |
---|---|
FeatherCache.set(key, val, opt) | returns Promise .key : stringval : any data to be stored opt : (optional) { maxAgeInMs: 1000 } , sets expiry time. |
FeatherCache.get(key) | returns Promise which resolves to the stored data. else, null . If data has expired returns null and then deletes the entry behind the scenes. |
FeatherCache.fetch(key) | returns Promise which resolves to stored data. The difference between get and fetch is that, fetch returns the stored data one more time after its expiry and then deletes it.More info: get : finds data -> if expired deletes it -> returns null .fetch : finds data -> if expired returns it -> and then deletes it . |
FeatherCache.del(key) | returns Promise deletes the entry |
A driver is nothing but a configuration object which exposes a persistent storage interface.
const dbDriver = {
maxAgeInMs: 60 * 1000 * 5, // default expiry 5 mins
setFn: async function(key, val) {
// db interface to store data
await Db.create({ key, val });
},
getFn: async function(key) {
// db interface to get data
const data = await Db.find({ where: { key } });
return data;
},
delFn: async function(key) {
// db interface to delete data
await Db.remove({ where: { key } });
},
};
// pass in the driver
const featherStore = new FeatherCache(dbDriver);
// ...
MIT © Vajahath Ahmed
FAQs
A Simple Lightweight Pluggable Key-Value Cache For Multiple Storage Options.
We found that feather-cache demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.