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

# getExtra(key)

### **Arguments**

1. `key` *(string)*: Key to get an extra by.

### **Lifecycle**

1. **preGetExtra**

   **Event name:** `preGetExtra`\
   **Properties passed:**

   * `cacheInstance` reference to cache instance (`this`)
   * `key` key passed to `getExtra` method

   **Returns:** *(object)*: object containing properties:

   * `cacheInstance` reference to cache instance (`this`)
   * `key` key passed through handlers added for `preGetExtra` event<br>
2. **postGetExtra**

   **Event name:** `postGetExtra`\
   **Properties passed:**

   * `cacheInstance` reference to cache instance (`this`) returned by `preGetExtra`
   * `key` key returned by `preGetExtra`
   * `extra` extra (object) returned by adapter using its [getExtra](/stash-it/api/adapter/getextra-key.md) method

   **Returns:** *(object)*: object containing properties:

   * `cacheInstance` reference to cache instance (`this`)
   * `key` key passed through handlers added for `postGetExtra` event
   * `extra` extra passed through handlers added for `postGetExtra` event<br>

   Eventually `getExtra` returns extra returned by `postGetExtra`.

{% hint style="info" %}
Even though `getExtra` uses `buildKey` internally, that build key is not passed in `postGetExtra` event handler's object's properties. If key is somehow changed (using some plugin) during `preBuildKey` or `postGetKey` events, that key is not passed further in `getExtra`. If you need access to built key, you can still obtain it from returned item to which you have access in `postGetExtra`.
{% endhint %}

{% hint style="info" %}
Make sure that `extra` exists when writing plugins, always. When `extra` is passed to event handler for this event, it might not exist anymore, and be `undefined`. Why? Some plugin before one you will use to operate on this extra, might have already removed item (from which this extra is taken from). How? Here's an example:

* you have a ttl plugin that will automatically remove an item once it's lifetime is over,
* you have another plugin that does something with this item's extra,
* order of executing plugins matter, therefore when first plugin will remove that item and pass `undefined` further down, every next plugin will operate on that undefined value. So do not try to access any property from that extra, your app will crash.
  {% endhint %}

### **Returns**

*(object)*: Object, extra from [item](/stash-it/basic-structure.md#extra).

*(undefined)*: If item is not found (thus no extra can be taken from it), returns `undefined`.

### **Example**

```javascript
// assuming that you already have cache instance prepared
cache.getExtra('key'); // object, extra for that item
cache.getExtra('keyForItemThatDoesNotExist'); // undefined
```
