# Hot Table Cache
__*Table cache*__
+ The amount of data in the table is small
+ Read-only tables or tables that are infrequently modify
+ The table is accessed very frequently

![right](./student-guide/diagram/HotSubtableCache_aa_001_20220509.png)

------------------------------------------------------------
TiDB introduced the cache table function in v6.0.0. This function is suitable for hot small tables that are frequently accessed and rarely modify. That is, the data of the entire table is loaded into the memory of the TiDB server, and the table data is obtained directly from the memory, avoiding fetching table data from TiKV, thus improving read performance.

We can use the following method to cache a table that has already been created in TiDB Server's memory:

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

The TiDB hotspot Table cache (cached table) function is suitable for tables with the following characteristics:
- The amount of data in the table is small
- Read-only table, or with few modify
- The table is accessed frequently, and better read performance is expected

When the amount of data in the table is small and the access is particularly frequent, the data will be concentrated on a TiKV region, forming a hot spot, which affects performance. Therefore, typical usage scenario for TiDB cache tables are as follows:
- Configuration table, through which the business reads configuration information
- A table that stores exchange rates in financial scenario. The table is not updated in real time and is only updated once a day
- Bank branch or branch information table, which rarely adds new records

Taking the configuration table as an example, when the business restart, all connections load the configuration together, which causes high database read latency. If you use a cached table, you can fix such a problem.

Points to note:

Since TiDB loads the data of the entire cache table into the memory of the TiDB process, and the cache becomes invalid after the modify operation is performed, it needs to be reloaded, so the TiDB cache table is only suitable for scenario the table is small.

Currently, TiDB has a limit of 64 MB per cache table. ALTER TABLE t CACHE will fail if the table has more than 64 MB of data.