# Plugins

A plugin is an object that consists of, at least, one property: `hooks` and / or `createExtensions`. Here is an example of full grown plugin (without the body):

```javascript
{
    hooks: [],
    createExtensions: ({ cacheInstance, getPreData, getPostData }) => {}
}
```

## **How to use a plugin? What do I get from it?**

If you take for example [stash-it-plugin-debug](https://github.com/smolak/stash-it-plugin-debug) you gain two things (read more on this plugin's repo page):

1. Data that flows in, through and out of each cache's method is going to be tracked (using passed callback, e.g. `console.log`).
2. Adds new method `runDiangnostics()`.

Here's how you use it:

```javascript
import createDebugPlugin from 'stash-it-plugin-debug';

// assuming that you already have cache instance
const debugPlugin = createDebugPlugin(console.log);
const cacheWithPlugins = cache.registerPlugins([ debugPlugin ]);

// without the plugin, this method would not be here
cacheWithPlugins.runDiagnostics(); // runs the diagnostics

cache.runDiagnostics(); // error, runDiagnostics is not a function
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stash-it.gitbook.io/stash-it/plugins.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
