# cache

## How to use

```jsx
import { Plugin } from '@root'

Plugin.cache({
    ...CACHE_PAYLOAD
})
```

## Cache payload

| Param        | Typeof   | Default | Required | Description                                                                |
| ------------ | -------- | ------- | :------: | -------------------------------------------------------------------------- |
| **key**      | String   | null    |     ✅    | the cache key to be used to save/get/remove your data from localStorage.   |
| **data**     | Any      | null    |     ✅    | the data item to be stored.                                                |
| **expire**   | Number   | 0       |     ❌    | when the data should be expired in localStorage                            |
| **callback** | Function | null    |     ❌    | a callback will be called when the data is saved/removed from localStorage |
| **method**   | String   | GET     |     ❌    | a method to save/get/remove available: `GET, POST, DELETE`                 |

## Save data to localStorage

```jsx
import { Plugin } from '@root'

const item = {
    id: 'item-id',
    name: 'item name'
}

const onSave = () => {

}

Plugin.cache({
    key: 'my-cache-key',
    data: item,
    method: 'POST',
    callback: onSave
})
```

####

## Get data from localStorage

```jsx
import { Plugin } from '@root'

const onGet = cachedData => {
    console.log(cachedData)
    /*
        Output:
        {
            id: 'item-id',
            name: 'item name'
        }
    */
}

Plugin.cache({
    key: 'my-cache-key',
    method: 'GET', // can be ignored, as GET is the default method for cache
    callback: onGet
})
```

## Remove data from localStorage

```jsx
import { Plugin } from '@root'

Plugin.cache({
    key: 'my-cache-key',
    method: 'DELETE'
})
```


---

# 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://docs.navigaglobal.com/dashboard-plugin/api-and-gui/api/cache.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.
