# @compass/cache

This package provides functionalities to interact with the Compass cache system. You can retrieve, set and manage cache data.

### Usage

```javascript
import cache from "@compass/cache";
```

### API Reference

#### `cache.get(key: string)`

Retrieves a value from the cache. Returns null if the key does not exist.

* `key` (required, string): The key to retrieve.

Returns a Promise that resolves with the value associated with the key in the cache.

#### `cache.set(key: string, value: any, ttl: number = 60 * 60)`

Sets a value in the cache. If a value already exists for the key, it will be overwritten.

* `key` (required, string): The key to set.
* `value` (required, any): The value to set.
* `ttl` (optional, number): The time to live in seconds. Defaults to 60 minutes (60 \* 60).

Returns a Promise that resolves once the key-value pair is successfully stored in the cache.

### Examples

To retrieve a value from the cache:

```javascript
import cache from "@compass/cache";

export default async function() {
    const key = 'myKey';
    const value = await cache.get(key);

    return {
      value,
    }
}
```

To set a value in the cache:

```javascript
import cache from "@compass/cache";

export default async function() {
    const key = 'myKey';
    const value = 'Hello, World!';
    const ttl = 60 * 60; // 1 hour

    await cache.set(key, value, ttl);
    
    return {
      success: true,
    }
}
```


---

# 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.compass.art/automations/custom-actions/compass-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.
