# Cached Table Overview

+ The data volume of the table is not large
+ Only read or modify tables that are not frequently changed
+ The reading access of the table is very frequent

![`smart`](HotSubtableCache_aa_002_20220509.png)

```
ALTER TABLE {table_name} ~!@CACHE@!~;
```

------------------------------------------------------------------------------
TiDB introduced the cache table feature in version 6.0.0. This feature is applicable to hot spot small tables that are frequently accessed and rarely modified, that is, loading the data of the entire table into the memory of the TiDB server, directly obtaining the table data from the memory, avoiding obtaining the table data from the TiKV server, thus improving the read performance.

We can use the following method to cache an already created table in the memory of the TiDB server:

```
CREATE TABLE users (
    id BIGINT,
    name VARCHAR(100),
    PRIMARY KEY(id)
);
ALTER TABLE users CACHE;
```

TiDB cache table feature is applicable to tables with the following characteristics:
- The data volume of the table is not large.
- Read only, or modify almost never.
- The access to the table is frequent, expecting better read performance.

When the data volume of the table is not large and the access is particularly frequent, the data will be concentrated on one Region of TiKV, forming a hotspot, thus affecting performance. Therefore, the typical usage scenarios of TiDB caching table are as follows:
- Static configuration table. Business reads configuration information through the configuration table.
- A table of stored exchange rates in a financial scene, which is not updated in real time, only updated once a day.
- Bank branches or retail outlets lookup table, this table rarely adds new record items.

For example, when the business restarts, all sessions load the configuration at the same time, which will cause higher database read latency. If a cache table is used, this problem can be solved.

Since TiDB loads the entire cached table data into the memory of the TiDB server, and the cache will be invalidated after modification operations, so it needs to be reloaded, TiDB cached table is only suitable for scenarios with relatively small tables.

Currently, TiDB limits the size of each cached table to 64 MB. If the table data exceeds 64 MB, executing the statement `ALTER TABLE ... CACHE` will fail.
