Add option for custom profiler
Closed this issue · 2 comments
First off, thank for writing such a great module. I love it.
I know the profiler is only for development purpose but it can do so much more. I would like to suggest the option to pass a custom profiler or listener. The current profiler ('memoizee/profiler') not only works as a global profiler but does not work when it is required after a function was memoized . In other words, any function memoized before require('memoizee/profiler')
is not profiled(correct me if I am wrong). This has some limitations.
What I am suggesting is an additional option so that we can have a different listener per function memoized. The listener (or profiler) can have a event handler for each of the configure-map (see ) events:
- set
- get
- delete
- clear
const listener = {
onGet: () => {
console.log('yay cache hit')
},
onSet: () => {
console.log('Oops, no caching used')
}
}
const memFn = memoizee(function(){
// ...
}, {listener})
The current profiler can be used as a default profiler:
- maybe when the profiler option is set true
- profileName is defined but no listener( or profiler) is provided
(still not sure what is best)
Example
Just a suggestion.
Thanks
@faboulaws can you explain well your use case, what exactly you want to achieve?
Here you propose a solution, but I'd love to know what problem we're really solving, that we way we can both pickup best solution :)
Also mind there's a v1 version design proposed, and in that version you'll be able to observe events for all cache operations per memoized function.
Still as delivery date of v1 is uncertain, I'll be happy to add some improvements to v0.4, assuming it doesn't require any significant work and doesn't break things.
@faboulaws as I didn't get any feedback I'm closing this. I also believe that all you need will be provided with v1