> For the complete documentation index, see [llms.txt](https://stash-it.gitbook.io/stash-it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stash-it.gitbook.io/stash-it/api/cacheinstance/addhook-hook.md).

# addHook(hook)

Hook is added to the end of the list. See [getHooks](/stash-it/api/cacheinstance/gethooks.md) method and [hooks in plugins](/stash-it/plugins/hooks.md).

### **Arguments**

1. `hook` *(Hook)*: An object with `event` and `handler` properties. See [plugins](/stash-it/plugins.md) for more info.

### **Throws**

1. If `event` is not a string, it will throw an error `Hook's event must be a string.`
2. If `event` doesn't begin with `pre` or `post`, it will throw an error `Hook's event must start with 'pre' or 'post'.`
3. If `handler` is not a function, it will throw an error `Hook's handler must be a function.`

### **Example**

```javascript
// assuming that you already have cache instance prepared
const hook = {
    event: 'preGetItem',
    handler: () => { ... } // some function that does something, not relevant here
}

cache.addHook(hook);
```
