or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

attack-detection.mdauthentication-management.mdcache-management.mdclient-configuration.mdclient-management.mdclient-policies.mdclient-scopes.mdcomponents.mdgroup-management.mdidentity-providers.mdindex.mdorganization-management.mdrealm-management.mdrole-management.mdserver-info.mduser-management.mduser-storage-provider.mdutility-functions.mdwhoami.md
tile.json

cache-management.mddocs/

0

# Cache Management

1

2

Cache management provides operations to clear various Keycloak caches, helping administrators refresh cached data and resolve caching-related issues in production environments.

3

4

## Capabilities

5

6

### Cache Clearing Operations

7

8

Clear specific types of caches to refresh system state.

9

10

```typescript { .api }

11

/**

12

* Clear the user cache for the realm

13

* @returns void

14

*/

15

clearUserCache(): Promise<void>;

16

17

/**

18

* Clear the keys cache for the realm

19

* @returns void

20

*/

21

clearKeysCache(): Promise<void>;

22

23

/**

24

* Clear the CRL (Certificate Revocation List) cache for the realm

25

* @returns void

26

*/

27

clearCrlCache(): Promise<void>;

28

29

/**

30

* Clear the realm cache

31

* @returns void

32

*/

33

clearRealmCache(): Promise<void>;

34

```

35

36

## Usage Examples

37

38

```typescript

39

import KeycloakAdminClient from "@keycloak/keycloak-admin-client";

40

41

const kcAdminClient = new KeycloakAdminClient({

42

baseUrl: 'http://localhost:8080',

43

realmName: 'myrealm',

44

});

45

46

await kcAdminClient.auth({

47

username: 'admin',

48

password: 'admin',

49

grantType: 'password',

50

clientId: 'admin-cli',

51

});

52

53

// Clear user cache (useful after user updates)

54

await kcAdminClient.cache.clearUserCache();

55

console.log('User cache cleared');

56

57

// Clear keys cache (useful after key rotation)

58

await kcAdminClient.cache.clearKeysCache();

59

console.log('Keys cache cleared');

60

61

// Clear CRL cache (useful after certificate updates)

62

await kcAdminClient.cache.clearCrlCache();

63

console.log('CRL cache cleared');

64

65

// Clear realm cache (useful after realm configuration changes)

66

await kcAdminClient.cache.clearRealmCache();

67

console.log('Realm cache cleared');

68

69

// Clear all caches sequentially

70

async function clearAllCaches() {

71

await kcAdminClient.cache.clearUserCache();

72

await kcAdminClient.cache.clearKeysCache();

73

await kcAdminClient.cache.clearCrlCache();

74

await kcAdminClient.cache.clearRealmCache();

75

console.log('All caches cleared');

76

}

77

78

await clearAllCaches();

79

```

80

81

## Common Use Cases

82

83

**After Configuration Changes**: Clear relevant caches after modifying realm settings, user attributes, or security configurations to ensure changes take effect immediately.

84

85

**Performance Troubleshooting**: Clear caches to resolve performance issues or stale data problems in production environments.

86

87

**Key Rotation**: Clear the keys cache after rotating signing keys or certificates to ensure new keys are immediately available.

88

89

**User Management**: Clear user cache after bulk user operations or identity provider synchronization to refresh user data.