---
type: api
title: Clear the user cache
description: Evict users from the user cache.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-clear-cached-realms
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-clear-cached-realms
products:
  - Elasticsearch
---

# Clear the user cache

Availability:

## Paths

- `POST` `/_security/realm/{realms}/_clear_cache`

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

#### Path Parameters

- `realms` (union Name | [] Name)
  A comma-separated list of realms.
To clear all realms, use an asterisk (`*`).
It does not support other wildcard patterns.

## Description

Evict users from the user cache.
You can completely clear the cache or evict specific users.

User credentials are cached in memory on each node to avoid connecting to a remote authentication service or hitting the disk for every incoming request.
There are realm settings that you can use to configure the user cache.
For more information, refer to the documentation about controlling the user cache.

[About controlling the user cache](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/controlling-user-cache)

## Query String Parameters

- `usernames` ([] string)
  A comma-separated list of the users to clear from the cache.
If you do not specify this parameter, the API evicts all users from the user cache.

## 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/realm/default_file/_clear_cache
```

#### JavaScript

```javascript
const response = await client.security.clearCachedRealms({
  realms: "default_file",
});
```

#### Python

```python
resp = client.security.clear_cached_realms(
    realms="default_file",
)
```

#### curl

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

#### Java

```java
client.security().clearCachedRealms(c -> c
    .realms("default_file")
);
```

#### C#

```c#
var response = await client.Security.ClearCachedRealmsAsync(realms: new[] { "default_file" });
```

#### PHP

```php
$resp = $client->security()->clearCachedRealms([
    "realms" => "default_file",
]);
```

#### Ruby

```ruby
response = client.security.clear_cached_realms(
  realms: "default_file"
)
```

