> For the complete documentation index, see [llms.txt](https://docs.iynxdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iynxdev.com/addon-api/getting-started/internal-api/cache.md).

# Cache

This page explains how to work with the internal Cache API.

## Cache API

Caches are an extended version of Discord’s [Collections](https://discord.js.org/docs/packages/discord.js/14.22.1/Collection:Class). They can be generated with the following snippet:

```js
this.heart.core.discord.core.cache.manager.register(new this.heart.core.discord.core.cache.interface(this.heart, '<cache_name>'));
```

Like any other component of the API, you can fetch and access caches used by Athena.

```js
const cache = this.heart.core.discord.core.cache.manager.get('<cache_name>');
```

### Functions

* `cache.getName()`: Returns the name of the cache.
* `cache.setPluginName(name)`: Sets the name of the plugin associated with this cache.
* `cache.getPluginName()`: Returns the name of the plugin associated with this cache.
* `cache.getPlugin()`: Returns the plugin instance associated with this cache.
* `cache.set(key, value)`: Stores a new entry in the cache under the given key.
* `cache.get(key)`: Retrieves the value stored under the given key. Returns `null` if the key does not exist.
* `cache.has(key)`: Returns `true` if the given key exists in the cache.
* `cache.delete(key)`: Removes the entry with the given key.
* `cache.deleteAfter(key)`: Marks the given key for deletion after a short delay.

> To access the raw Discord Collection instance used by the cache, use `cache.cache`.
