Skip to content

Instantly share code, notes, and snippets.

@Cadienvan
Created April 3, 2023 15:14
Show Gist options
  • Save Cadienvan/fda1dc6eb032b0fdbc99806301dbacdd to your computer and use it in GitHub Desktop.
Save Cadienvan/fda1dc6eb032b0fdbc99806301dbacdd to your computer and use it in GitHub Desktop.
Cache Candidate Example Internals
const { cacheCandidate } = require("@jointly/cache-candidate");
const myFn = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Hello World');
}, 1000);
});
}
const cachedMyFn = cacheCandidate(myFn, {
plugins: [
{
name: 'myPlugin',
hooks: [
{
hook: 'SETUP',
action: (payload) => {
payload.internals.getDataCacheKey = () => {
return 'abc';
}
console.log('SETUP');
}
},
{
hook: 'EXECUTION_PRE',
action: (payload) => {
console.log('EXECUTION_PRE', payload.internals.getDataCacheKey());
}
}
]
}
]
});
cachedMyFn();
cachedMyFn();
cachedMyFn();
cachedMyFn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment