
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
A Promise based caching library for node or the browser.
Pass in a cache key, a promise executor and optionally a cache length and get back a cached object.
Medusa supports
npm install medusajs
var Medusa = require('medusajs');
function ex() {
return Medusa.get('sample', function(resolve, reject) {
console.log('cache miss');
resolve('example');
}, 1000);
}
ex().then(res => {
console.log(res);
});
ex().then(res => {
console.log(res);
});
ex().then(res => {
console.log(res);
});
/* returns:
cache miss
example
example
example */
The function will lookup and resolve the value for the previously resolved promise, if no entry is in the cache the function will resolve the promise and resolve that.
rejected promises are not cached.
The policy value will set the duration of the cache, if no policy is set the object will be cache until cleared manually.
The function will resolve the value for the promise and store that result in place of the current object. The original object will be available while the promise resolves.
rejected promises are not cached.
The policy value will set the duration of the cache, if no policy is set the object will be cache until cleared manually.
Bypass the get function and store an object directly into the cache.
Clear a cached item, if no key is set all items will be cleared. Returns a promise that will resolve to true if successful, or an array of booleans for each key; if provider is not specified it will clear the default provider only.
You may also clear cache items using a wildcard characters e.g. Medusa.clear('sample*')
Send in an updated settings object:
The simplest policy is to simply set a duration, pass in any integer and the object will be cached for that many miliseconds.
Medusa.get('sample', resolver, 1000).then(res => { console.log(res); });
If you have a specific date and time you would like a cache item to expire, you can pass in a date object
var midnight = new Date();
midnight.setHours(24,0,0,0); // midnight
Medusa.get('sample', resolver, midnight).then(res => { console.log(res); });
If you have something more complex you would like to do with the policy, you can pass in an object with your specifications.
expiry: Date or amount of miliseconds you would like the cache to expire (required but may be set to false)provider: Specify the provider to use (default: 'memory')Medusa.get('sample', resolver, {
expiry: 1000,
provider: 'memory',
}).then(res => { console.log(res); });
var Medusa = require('medusajs');
var storageCache = require('medusajs/storageObjectProvider');
storageCache.setStorage(window.sessionStorage);
Medusa.addProvider('session', storageCache);
as of MedusaJS v1.1.0 if you request 2 calls at the same time, the resolver will only resolve once no matter how long the resolver takes. Making a slow API call will now only call the API once even if you request the information more then once in a short period.
FAQs
a promise based caching library
We found that medusajs 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.