# Reset Database Cache API

> Drop the cached answers of the APIs of a table, a database or an instance with the reset database cache system API of API Maker, for one tenant or all of them.

Source: https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-reset-redis-cache-db-api.html

Drops the cached answers of the generated and schema APIs of a table, of every table of a database, or of every database of an instance. Writes through API Maker do it on their own ; this API is for data changed outside API Maker, or a cache you want gone now.

| | |
|---|---|
| Method | POST |
| URL | `/api/system-api/admin/reset-redis-cache-db` : `admin` is the user path of your account |
| Body | `{ instance, database?, collection? }` or an array of them |
| Answer | `data` : the number of cache entries removed, or an array of numbers |
| From code | [`g.sys.cache.resetCacheDB`](https://docs.apimaker.dev/v1/examples/sys/cache/resetCacheDB.html) |

## The call

**Body : one table**

```json
{ "instance": "mysql8", "database": "inventory", "collection": "customers" }
```

**Body : every table of a database**

```json
{ "instance": "mysql8", "database": "inventory" }
```

**Body : several at once**

```json
[
    { "instance": "mysql8", "database": "inventory", "collection": "customers" },
    { "instance": "mongodb", "database": "shop", "collection": "orders" }
]
```

**Answer**

```json
{ "success": true, "statusCode": 200, "data": 1 }
```

- `table` works in place of `collection`.
- An array body answers an array of counts in the same order ; an unknown instance gives `-1` there and a `404` in `errors`.

## One tenant

```json
{ "instance": "crm::acme", "database": "crm", "collection": "customers" }
```

- Names the tenant after the instance : only the cached answers of `acme` go. Without a tenant, the cache of the table is reset for the structure database and every tenant. See [Multi-tenant](https://docs.apimaker.dev/v1/docs/features/multi-tenant.html#caching).

## From code

```typescript
await g.sys.cache.resetCacheDB({ instance: 'mysql8', database: 'inventory', collection: 'customers' });
```

- One call for one answer : the header [`x-am-cache-control: reset_cache`](https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-cache-control) on the read itself.

## Access and settings

- Over HTTP, a system API answers once its [settings](https://docs.apimaker.dev/v1/docs/settings/systemApiSettings.html) give it `apiAccessType: TOKEN_ACCESS` (the token of an API user whose [group](https://docs.apimaker.dev/v1/docs/apis-security/api-group-permission.html) grants this system API, in `x-am-authorization`) or `IS_PUBLIC`. Without settings it is `NO_ACCESS` : your code calls it through `g.sys`, the admin panel tests it, and an HTTP call is refused.
- The settings can also cache the answer or require person tokens (`authProviders`) ; [pre and post hooks](https://docs.apimaker.dev/v1/docs/apis-all/hooks/preHook-api.html) run around it like around any API.
- The [request headers](https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html) apply : `x-am-response-case`, `x-am-content-type-response`, `x-am-internationalization`, `x-am-tenant-username`…

## Errors

| Code | When |
|---|---|
| `400` | The body is wrong : the message names the missing or invalid key. |
| `401` | No valid API user token, or the API is `NO_ACCESS` : `You are not authorized to access this API.` |
| `403` | No group grants this system API. |

## Related

- [All APIs at a glance](https://docs.apimaker.dev/v1/docs/apis-all/overview.html) · [Response format](https://docs.apimaker.dev/v1/docs/apis-all/response-format.html) · [System API settings](https://docs.apimaker.dev/v1/docs/settings/systemApiSettings.html) · [System APIs from code](https://docs.apimaker.dev/v1/examples/sys/system/system.html)
