or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cache.mddatabase.mddebug.mdentities.mdhelper-api.mdindex.mdmigrations.mdschema.mdseeders.md

cache.mddocs/

0

# Cache Commands

1

2

MikroORM CLI cache management commands for handling metadata cache operations. The metadata cache improves startup performance by caching entity metadata discovery results.

3

4

## Capabilities

5

6

### Clear Metadata Cache

7

8

Clears the existing metadata cache. Useful when metadata has changed or cache corruption is suspected.

9

10

```typescript { .api }

11

/**

12

* Clear metadata cache command

13

*/

14

command: "cache:clear"

15

16

// No additional options beyond global options

17

```

18

19

**Usage Examples:**

20

21

```bash

22

# Clear cache with default configuration

23

mikro-orm cache:clear

24

25

# Clear cache with specific config file

26

mikro-orm cache:clear --config ./custom-config.js

27

28

# Clear cache for specific context

29

mikro-orm cache:clear --context production

30

```

31

32

### Generate Metadata Cache

33

34

Generates metadata cache for improved application startup performance. Supports both development and production cache formats.

35

36

```typescript { .api }

37

/**

38

* Generate metadata cache command

39

*/

40

command: "cache:generate"

41

42

interface CacheGenerateOptions extends BaseArgs {

43

ts?: boolean; // Use ts-node to generate '.ts' cache

44

tsNode?: boolean; // Alias for ts

45

combined?: string; // Generate production cache into single JSON file

46

c?: string; // Alias for combined

47

}

48

```

49

50

**Usage Examples:**

51

52

```bash

53

# Generate standard cache

54

mikro-orm cache:generate

55

56

# Generate TypeScript cache for development

57

mikro-orm cache:generate --ts-node

58

59

# Generate production cache into single file

60

mikro-orm cache:generate --combined

61

62

# Generate cache with custom config

63

mikro-orm cache:generate --config ./orm.config.js --combined

64

```

65

66

## Command Options

67

68

### Global Options

69

70

All cache commands support:

71

- `--config` / `-c`: Path to ORM configuration file(s)

72

- `--contextName` / `--context`: Configuration context name

73

74

### cache:generate Options

75

76

- `--ts-node` / `--ts`: Generate TypeScript-compatible cache (for development)

77

- `--combined` / `-c`: Generate production cache into single JSON file that can be used with GeneratedCacheAdapter

78

79

## Error Handling

80

81

### cache:clear Errors

82

83

- **Cache not enabled**: If metadata cache is disabled in configuration, the command will display an error message and exit

84

- **Configuration errors**: Invalid or missing configuration will prevent cache operations

85

86

### cache:generate Errors

87

88

- **Entity discovery failures**: Problems discovering entities will prevent cache generation

89

- **File system errors**: Insufficient permissions or disk space can cause cache generation to fail

90

- **TypeScript compilation errors**: When using `--ts-node`, TypeScript compilation issues will prevent cache generation

91

92

## Related Configuration

93

94

Cache commands work with these MikroORM configuration options:

95

96

```typescript { .api }

97

interface CacheConfiguration {

98

metadataCache: {

99

enabled: boolean; // Enable/disable cache

100

adapter: CacheAdapter; // Cache adapter instance

101

options?: {

102

combined?: string; // Path for combined cache file

103

};

104

};

105

}

106

```