---
type: api
title: Clear the roles cache
description: Evict roles from the native role cache.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-security-clear-cached-roles
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-security-clear-cached-roles
products:
  - Elasticsearch
---

# Clear the roles cache

Availability:

## Paths

- `POST` `/_security/role/{name}/_clear_cache`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#bearerauth)

#### Path Parameters

- `name` (union Name | [] Name)
  A comma-separated list of roles to evict from the role cache.
To evict all roles, use an asterisk (`*`).
It does not support other wildcard patterns.

## Description

Evict roles from the native role cache.

## Required authorization

* Cluster privileges: `manage_security`

## Response

`application/json`

- `_nodes` ({} NodeStatistics)
  - `failures` ([] ErrorCause)
    - `type` (string)
      The type of error
    - `reason` (union string) — nullable
      A human-readable explanation of the error, in English.
      One of: `string`
    - `stack_trace` (string)
      The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
    - `caused_by` ({} ErrorCause) — recursive
      Same fields as `failures` in `_nodes`
    - `root_cause` ([] ErrorCause) — recursive
      Same fields as `failures` in `_nodes`
    - `suppressed` ([] ErrorCause) — recursive
      Same fields as `failures` in `_nodes`
  - `total` (number)
    Total number of nodes selected by the request.
  - `successful` (number)
    Number of nodes that responded successfully to the request.
  - `failed` (number)
    Number of nodes that rejected the request or failed to respond. If this value is not 0, a reason for the rejection or failure is included in the response.
- `cluster_name` (string Name)
- `nodes` (map string to ClusterNode)
  Map values ({} ClusterNode)
  - `name` (string Name)
## Code Examples

#### Console

```console
POST /_security/role/my_admin_role/_clear_cache
```

#### JavaScript

```javascript
const response = await client.security.clearCachedRoles({
  name: "my_admin_role",
});
```

#### Python

```python
resp = client.security.clear_cached_roles(
    name="my_admin_role",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_security/role/my_admin_role/_clear_cache" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().clearCachedRoles(c -> c
    .name("my_admin_role")
);
```

#### C#

```c#
var response = await client.Security.ClearCachedRolesAsync(name: new[] { "my_admin_role" });
```

#### PHP

```php
$resp = $client->security()->clearCachedRoles([
    "name" => "my_admin_role",
]);
```

#### Ruby

```ruby
response = client.security.clear_cached_roles(
  name: "my_admin_role"
)
```

