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

# removeItem(key)

Removes an item.

### **Arguments**

1. `key` *(string)*: Key to remove an item by.

### **Lifecycle**

1. **preRemoveItem**

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

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

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

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

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

   * `cacheInstance` reference to cache instance (`this`) returned by `preRemoveItem`
   * `key` key returned by `preRemoveItem`
   * `result` boolean value returned by adapter using its [removeItem](/stash-it/api/adapter/removeitem-key.md) method

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

   * `cacheInstance` reference to cache instance (`this`)
   * `key` key passed through handlers added for `postRemoveItem` event
   * `result` boolean value passed through handlers added for `postRemoveItem` event<br>

   Eventually `removeItem` returns result returned by `postRemoveItem`.

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

### **Returns**

*(bool)*: `true` if item was removed, `false` otherwise.

### **Example**

```javascript
// assuming that you already have cache instance prepared
cache.removeItem('key'); // true
cache.removeItem('keyForItemThatDoesNotExist'); // false
```
