## Cache
**Kind**: global class
* [Cache](#Cache)
* [new Cache([options])](#new_Cache_new)
* [.length](#Cache#length) : number
* [.hasKey(key)](#Cache#hasKey) ⇒ boolean
* [.setItem(key, item, [options])](#Cache#setItem) ⇒ [Cache](#Cache)
* [.getItem(key, [defaultValue])](#Cache#getItem) ⇒ \*
* [.removeItem(key)](#Cache#removeItem) ⇒ [Cache](#Cache)
* [.setLimit(limit)](#Cache#setLimit) ⇒ [Cache](#Cache)
* [.clear()](#Cache#clear) ⇒ [Cache](#Cache)
* [.key(n)](#Cache#key) ⇒ string
### new Cache([options])
Creates a new Cache.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | object | | Possible options to use |
| [options.limit] | number | no limit | Maximum size of the cache. |
| [options.storage] | object | internal storage | Replace the storage engine (localStorage, sessionStorage or any object). |
| [options.keyPrefix] | string | "cache#{index}:" | If options.storage is set, namespace all storage keys to avoid conflicts. of data items stored in the storage object. |
| [options.expires] | date | timestamp | | Set an expiry date. After this date, all items will be removed. |
| [options.maxAge] | maxAge | | Set the time in milliseconds for when the current data items will be removed |
### cache.length : number
Returns an integer representing the number
of data items stored
**Kind**: instance property of [Cache](#Cache)
### cache.hasKey(key) ⇒ boolean
Return true if the given key is present in storage
**Kind**: instance method of [Cache](#Cache)
| Param | Type |
| --- | --- |
| key | string |
### cache.setItem(key, item, [options]) ⇒ [Cache](#Cache)
When passed a key name and value, will add that key to the storage,
or update that key's value if it already exists (note that, in this case,
the key order will be updated as well).
Purge the storage if the number of items exceed the limit.
**Kind**: instance method of [Cache](#Cache)
| Param | Type | Description |
| --- | --- | --- |
| key | string | |
| item | \* | |
| [options] | object | Possible options to use |
| [options.expires] | date | timestamp | Set an expiry date for this item. After this date, the item will be removed. |
| [options.maxAge] | maxAge | Set the time in milliseconds for when this item will be removed. |
### cache.getItem(key, [defaultValue]) ⇒ \*
When passed a key name, will return that key's value.
If no value is found, return undefined or the given defaultValue.
**Kind**: instance method of [Cache](#Cache)
**Returns**: \* - item - /!\ The type of item will be a string if the storage is
localStorage or sessionStorage.
| Param | Type |
| --- | --- |
| key | string |
| [defaultValue] | \* |
### cache.removeItem(key) ⇒ [Cache](#Cache)
When passed a key name, will remove that key from the storage.
**Kind**: instance method of [Cache](#Cache)
| Param | Type |
| --- | --- |
| key | string |
### cache.setLimit(limit) ⇒ [Cache](#Cache)
Set the maximum size of the storage.
Remove the oldest elements if the storage limit is reached.
**Kind**: instance method of [Cache](#Cache)
| Param | Type | Description |
| --- | --- | --- |
| limit | number | A positive number |
### cache.clear() ⇒ [Cache](#Cache)
Empty all keys out of the storage.
**Kind**: instance method of [Cache](#Cache)
### cache.key(n) ⇒ string
Return the name of the nth key in the storage.
**Kind**: instance method of [Cache](#Cache)
| Param | Type |
| --- | --- |
| n | number |