> For the complete documentation index, see [llms.txt](https://cross-packages.gitbook.io/cross-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cross-packages.gitbook.io/cross-api/providers/cache.md).

# Cache

A caching implementation to make the system more fluid and not always rely on SQL operations.

## Available:

* Redis
* Fake

## Methods:

**Save:** Caches a value passed in a key.

```typescript
const data = { message: 'data' };

await this.cacheProvider.save(
    {
        prefix: 'messages',
        suffix: 'key:id=123',
    },
    data,
);
```

**SaveTemporary:** Caches a value passed in a key for a limited time.

```typescript
const data = { message: 'data' };

await this.cacheProvider.saveTemporary(
    {
        prefix: 'messages',
        suffix: 'key:id=123',
    },
    data,
    '7d',
);
```

**Recovery:** Retrieves cached data from a key.

```typescript
const data = await this.cacheProvider.recovery({
    prefix: 'messages',
    suffix: 'key:id=123',
});
```

**Invalidate:** Deletes a specific key value set.

```typescript
await this.cacheProvider.invalidate({
    prefix: 'messages',
    suffix: 'key:id=123',
});
```

**InvalidatePrefix:** Deletes all key value sets started by the passed key.

```typescript
await this.cacheProvider.invalidatePrefix('key');
```

**Close:** It's used to close the connection with Redis.

```typescript
this.cacheProvider.close();
```

***
