<commit_before>[role="xpack"]
[[security-api-clear-cache]]
=== Clear Cache API

The Clear Cache API evicts users from the user cache. You can completely clear
the cache or evict specific users.

For example, to evict all users cached by the `file` realm:

[source,js]
--------------------------------------------------
POST _xpack/security/realm/default_file/_clear_cache
--------------------------------------------------
// CONSOLE

To evict selected users, specify the `usernames` parameter:

[source,js]
--------------------------------------------------
POST _xpack/security/realm/default_file/_clear_cache?usernames=rdeniro,alpacino
--------------------------------------------------
// CONSOLE

To clear the caches for multiple realms, specify the realms as a comma-delimited
list:

[source, js]
------------------------------------------------------------
POST _xpack/security/realm/default_file,ldap1/_clear_cache
------------------------------------------------------------
// CONSOLE

For more information, see 
{xpack-ref}/controlling-user-cache.html[Controlling the User Cache].
<commit_msg>[DOCS] Format the clear cache API (elastic/x-pack-elasticsearch#2574)<commit_after>[role="xpack"]
[[security-api-clear-cache]]
=== Clear Cache API

The Clear Cache API evicts users from the user cache. You can completely clear
the cache or evict specific users.

==== Request

`POST _xpack/security/realm/<realms>/_clear_cache` +

`POST _xpack/security/realm/<realms>/_clear_cache?usernames=<usernames>`


==== Description

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, see {xpack-ref}/controlling-user-cache.html[Controlling the User Cache].

==== Path Parameters

`realms` (required)::
  (list) A comma-separated list of the realms to clear.

`usernames`::
  (list) 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.

==== Examples

For example, to evict all users cached by the `file` realm:

[source,js]
--------------------------------------------------
POST _xpack/security/realm/default_file/_clear_cache
--------------------------------------------------
// CONSOLE

To evict selected users, specify the `usernames` parameter:

[source,js]
--------------------------------------------------
POST _xpack/security/realm/default_file/_clear_cache?usernames=rdeniro,alpacino
--------------------------------------------------
// CONSOLE

To clear the caches for multiple realms, specify the realms as a comma-delimited
list:

[source, js]
------------------------------------------------------------
POST _xpack/security/realm/default_file,ldap1/_clear_cache
------------------------------------------------------------
// CONSOLE

{'fraction_non_alphanumeric': 0.29053133514986373, 'fraction_numerical': 0.0020435967302452314, 'mean_word_length': 1.8597857838364167, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '520247', 'n_tokens_mistral': 753, 'n_tokens_neox': 737, 'n_words': 251}