---
description: Builds a key.
---

# buildKey(key)

### **Arguments**

1. `key` _(string)_: String to build a key of.

### **Lifecycle**

1.  **preBuildKey**

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

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

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

    * `cacheInstance` reference to cache instance (`this`)
    * `key` key passed through handlers added for `preBuildKey` event\

2.  **postBuildKey**

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

    * `cacheInstance` reference to cache instance (`this`) returned by `preBuildKey`
    * `key` key built by adapter using its [buildKey](../adapter/buildkey-key) method

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

    * `cacheInstance` reference to cache instance (`this`)
    * `key` key passed through handlers added for `postBuildKey` event

    \
    Eventually `buildKey` returns key returned by `postBuildKey`.

### **Returns**

_(string)_: Built key. Depends on adapter being used.

### **Example**

```javascript
// assuming that you already have cache instance prepared
const builtKey = cache.buildKey('key');
```
