> 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/gethooks.md).

# getHooks()

Returns hooks.

### **Returns**

*(object)*: Object with hooks.

Hooks, when added, are stored in an object. Properties of that object are hook's events and values are arrays of handlers.

### **Examples**

```javascript
// 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 ]);

// In cache, hooks will be stored like so:
{
    hooks: {
        preGetItem: [
            () => {} // handler from hook1
        ],
        postSetItem: [
            () => {} // handler from hook2
        ]
    }
}

cache.getHooks(); // it will return object shown above
```

### **What will happen when I will add more hooks with same event names?**

```javascript
// continuing from the example above
const hook3 = {
    event: 'preGetItem',
    handler: () => {}
}

cache.addHook(hook3);

//right now hooks will look like so:
{
    hooks: {
        preGetItem: [
            () => {} // handler from hook1,
            () => {} // handler from hook3, added to the end of the list of hooks for given event
        ],
        postSetItem: [
            () => {} // handler from hook2
        ]
    }
}
```
