addHooks(hooks)
Adds hooks.
Hooks are added to the end of the hooks list. See getHooks method and hooks in plugins.
Arguments
hooks(array): Array of hooks.
Throws
If
eventfor any hook is not a string, it will throw an errorHook's event must be a string.If
eventfor any hook doesn't begin withpreorpost, it will throw an errorHook's event must start with 'pre' or 'post'.If
handlerfor any hook is not a function, it will throw an errorHook's handler must be a function.
Example
// assuming that you already have cache instance prepared
const hook1 = {
event: 'preGetItem',
handler: () => { ... } // some function that does something, not relevant here
}
const hook2 = {
event: 'postSetItem',
handler: () => { ... } // some function that does something, not relevant here
}
cache.addHooks([ hook1, hook2 ]);Last updated