Created
April 3, 2023 15:14
-
-
Save Cadienvan/fda1dc6eb032b0fdbc99806301dbacdd to your computer and use it in GitHub Desktop.
Cache Candidate Example Internals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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